Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- TypeSystemClang.cpp -----------------------------------------------===//
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
#include "TypeSystemClang.h"
10
11
#include "llvm/Support/FormatAdapters.h"
12
#include "llvm/Support/FormatVariadic.h"
13
14
#include <mutex>
15
#include <string>
16
#include <vector>
17
18
#include "clang/AST/ASTContext.h"
19
#include "clang/AST/ASTImporter.h"
20
#include "clang/AST/Attr.h"
21
#include "clang/AST/CXXInheritance.h"
22
#include "clang/AST/DeclObjC.h"
23
#include "clang/AST/DeclTemplate.h"
24
#include "clang/AST/Mangle.h"
25
#include "clang/AST/RecordLayout.h"
26
#include "clang/AST/Type.h"
27
#include "clang/AST/VTableBuilder.h"
28
#include "clang/Basic/Builtins.h"
29
#include "clang/Basic/Diagnostic.h"
30
#include "clang/Basic/FileManager.h"
31
#include "clang/Basic/FileSystemOptions.h"
32
#include "clang/Basic/LangStandard.h"
33
#include "clang/Basic/SourceManager.h"
34
#include "clang/Basic/TargetInfo.h"
35
#include "clang/Basic/TargetOptions.h"
36
#include "clang/Frontend/FrontendOptions.h"
37
#include "clang/Lex/HeaderSearch.h"
38
#include "clang/Lex/HeaderSearchOptions.h"
39
#include "clang/Lex/ModuleMap.h"
40
#include "clang/Sema/Sema.h"
41
42
#include "llvm/Support/Signals.h"
43
#include "llvm/Support/Threading.h"
44
45
#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
46
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
47
#include "Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h"
48
#include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h"
49
#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
50
#include "Plugins/ExpressionParser/Clang/ClangUserExpression.h"
51
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
52
#include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h"
53
#include "lldb/Utility/ArchSpec.h"
54
#include "lldb/Utility/Flags.h"
55
56
#include "lldb/Core/DumpDataExtractor.h"
57
#include "lldb/Core/Module.h"
58
#include "lldb/Core/PluginManager.h"
59
#include "lldb/Core/StreamFile.h"
60
#include "lldb/Core/ThreadSafeDenseMap.h"
61
#include "lldb/Core/UniqueCStringMap.h"
62
#include "lldb/Symbol/ObjectFile.h"
63
#include "lldb/Symbol/SymbolFile.h"
64
#include "lldb/Target/ExecutionContext.h"
65
#include "lldb/Target/Language.h"
66
#include "lldb/Target/Process.h"
67
#include "lldb/Target/Target.h"
68
#include "lldb/Utility/DataExtractor.h"
69
#include "lldb/Utility/LLDBAssert.h"
70
#include "lldb/Utility/Log.h"
71
#include "lldb/Utility/RegularExpression.h"
72
#include "lldb/Utility/Scalar.h"
73
74
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
75
#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
76
#include "Plugins/SymbolFile/PDB/PDBASTParser.h"
77
78
#include <cstdio>
79
80
#include <mutex>
81
82
using namespace lldb;
83
using namespace lldb_private;
84
using namespace clang;
85
using llvm::StringSwitch;
86
87
LLDB_PLUGIN_DEFINE(TypeSystemClang)
88
89
namespace {
90
97.1k
static void VerifyDecl(clang::Decl *decl) {
91
97.1k
  assert(decl && "VerifyDecl called with nullptr?");
92
0
#ifndef NDEBUG
93
  // We don't care about the actual access value here but only want to trigger
94
  // that Clang calls its internal Decl::AccessDeclContextCheck validation.
95
0
  decl->getAccess();
96
97.1k
#endif
97
97.1k
}
98
99
static inline bool
100
8.49k
TypeSystemClangSupportsLanguage(lldb::LanguageType language) {
101
8.49k
  return language == eLanguageTypeUnknown || // Clang is the default type system
102
8.49k
         
lldb_private::Language::LanguageIsC(language)8.46k
||
103
8.49k
         
lldb_private::Language::LanguageIsCPlusPlus(language)4.55k
||
104
8.49k
         
lldb_private::Language::LanguageIsObjC(language)766
||
105
8.49k
         
lldb_private::Language::LanguageIsPascal(language)2
||
106
         // Use Clang for Rust until there is a proper language plugin for it
107
8.49k
         
language == eLanguageTypeRust2
||
108
8.49k
         
language == eLanguageTypeExtRenderScript2
||
109
         // Use Clang for D until there is a proper language plugin for it
110
8.49k
         
language == eLanguageTypeD2
||
111
         // Open Dylan compiler debug info is designed to be Clang-compatible
112
8.49k
         
language == eLanguageTypeDylan1
;
113
8.49k
}
114
115
// Checks whether m1 is an overload of m2 (as opposed to an override). This is
116
// called by addOverridesForMethod to distinguish overrides (which share a
117
// vtable entry) from overloads (which require distinct entries).
118
50
bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
119
  // FIXME: This should detect covariant return types, but currently doesn't.
120
50
  lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
121
50
             "Methods should have the same AST context");
122
50
  clang::ASTContext &context = m1->getASTContext();
123
124
50
  const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
125
50
      context.getCanonicalType(m1->getType()));
126
127
50
  const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
128
50
      context.getCanonicalType(m2->getType()));
129
130
50
  auto compareArgTypes = [&context](const clang::QualType &m1p,
131
50
                                    const clang::QualType &m2p) {
132
3
    return context.hasSameType(m1p.getUnqualifiedType(),
133
3
                               m2p.getUnqualifiedType());
134
3
  };
135
136
  // FIXME: In C++14 and later, we can just pass m2Type->param_type_end()
137
  //        as a fourth parameter to std::equal().
138
50
  return (m1->getNumParams() != m2->getNumParams()) ||
139
50
         !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
140
41
                     m2Type->param_type_begin(), compareArgTypes);
141
50
}
142
143
// If decl is a virtual method, walk the base classes looking for methods that
144
// decl overrides. This table of overridden methods is used by IRGen to
145
// determine the vtable layout for decl's parent class.
146
59.6k
void addOverridesForMethod(clang::CXXMethodDecl *decl) {
147
59.6k
  if (!decl->isVirtual())
148
59.3k
    return;
149
150
250
  clang::CXXBasePaths paths;
151
250
  llvm::SmallVector<clang::NamedDecl *, 4> decls;
152
153
250
  auto find_overridden_methods =
154
250
      [&decls, decl](const clang::CXXBaseSpecifier *specifier,
155
250
                     clang::CXXBasePath &path) {
156
123
        if (auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
157
123
                specifier->getType()->getAs<clang::RecordType>()->getDecl())) {
158
159
123
          clang::DeclarationName name = decl->getDeclName();
160
161
          // If this is a destructor, check whether the base class destructor is
162
          // virtual.
163
123
          if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
164
41
            if (auto *baseDtorDecl = base_record->getDestructor()) {
165
31
              if (baseDtorDecl->isVirtual()) {
166
31
                decls.push_back(baseDtorDecl);
167
31
                return true;
168
31
              } else
169
0
                return false;
170
31
            }
171
172
          // Otherwise, search for name in the base class.
173
92
          for (path.Decls = base_record->lookup(name).begin();
174
101
               path.Decls != path.Decls.end(); 
++path.Decls9
) {
175
50
            if (auto *method_decl =
176
50
                    llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
177
50
              if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
178
41
                decls.push_back(method_decl);
179
41
                return true;
180
41
              }
181
50
          }
182
92
        }
183
184
51
        return false;
185
123
      };
186
187
250
  if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
188
69
    for (auto *overridden_decl : decls)
189
72
      decl->addOverriddenMethod(
190
72
          llvm::cast<clang::CXXMethodDecl>(overridden_decl));
191
69
  }
192
250
}
193
}
194
195
static lldb::addr_t GetVTableAddress(Process &process,
196
                                     VTableContextBase &vtable_ctx,
197
                                     ValueObject &valobj,
198
16
                                     const ASTRecordLayout &record_layout) {
199
  // Retrieve type info
200
16
  CompilerType pointee_type;
201
16
  CompilerType this_type(valobj.GetCompilerType());
202
16
  uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
203
16
  if (!type_info)
204
0
    return LLDB_INVALID_ADDRESS;
205
206
  // Check if it's a pointer or reference
207
16
  bool ptr_or_ref = false;
208
16
  if (type_info & (eTypeIsPointer | eTypeIsReference)) {
209
14
    ptr_or_ref = true;
210
14
    type_info = pointee_type.GetTypeInfo();
211
14
  }
212
213
  // We process only C++ classes
214
16
  const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
215
16
  if ((type_info & cpp_class) != cpp_class)
216
0
    return LLDB_INVALID_ADDRESS;
217
218
  // Calculate offset to VTable pointer
219
16
  lldb::offset_t vbtable_ptr_offset =
220
16
      vtable_ctx.isMicrosoft() ? 
record_layout.getVBPtrOffset().getQuantity()0
221
16
                               : 0;
222
223
16
  if (ptr_or_ref) {
224
    // We have a pointer / ref to object, so read
225
    // VTable pointer from process memory
226
227
14
    if (valobj.GetAddressTypeOfChildren() != eAddressTypeLoad)
228
0
      return LLDB_INVALID_ADDRESS;
229
230
14
    auto vbtable_ptr_addr = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
231
14
    if (vbtable_ptr_addr == LLDB_INVALID_ADDRESS)
232
0
      return LLDB_INVALID_ADDRESS;
233
234
14
    vbtable_ptr_addr += vbtable_ptr_offset;
235
236
14
    Status err;
237
14
    return process.ReadPointerFromMemory(vbtable_ptr_addr, err);
238
14
  }
239
240
  // We have an object already read from process memory,
241
  // so just extract VTable pointer from it
242
243
2
  DataExtractor data;
244
2
  Status err;
245
2
  auto size = valobj.GetData(data, err);
246
2
  if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size)
247
0
    return LLDB_INVALID_ADDRESS;
248
249
2
  return data.GetAddress(&vbtable_ptr_offset);
250
2
}
251
252
static int64_t ReadVBaseOffsetFromVTable(Process &process,
253
                                         VTableContextBase &vtable_ctx,
254
                                         lldb::addr_t vtable_ptr,
255
                                         const CXXRecordDecl *cxx_record_decl,
256
16
                                         const CXXRecordDecl *base_class_decl) {
257
16
  if (vtable_ctx.isMicrosoft()) {
258
0
    clang::MicrosoftVTableContext &msoft_vtable_ctx =
259
0
        static_cast<clang::MicrosoftVTableContext &>(vtable_ctx);
260
261
    // Get the index into the virtual base table. The
262
    // index is the index in uint32_t from vbtable_ptr
263
0
    const unsigned vbtable_index =
264
0
        msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
265
0
    const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
266
0
    Status err;
267
0
    return process.ReadSignedIntegerFromMemory(base_offset_addr, 4, INT64_MAX,
268
0
                                               err);
269
0
  }
270
271
16
  clang::ItaniumVTableContext &itanium_vtable_ctx =
272
16
      static_cast<clang::ItaniumVTableContext &>(vtable_ctx);
273
274
16
  clang::CharUnits base_offset_offset =
275
16
      itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
276
16
                                                    base_class_decl);
277
16
  const lldb::addr_t base_offset_addr =
278
16
      vtable_ptr + base_offset_offset.getQuantity();
279
16
  const uint32_t base_offset_size = process.GetAddressByteSize();
280
16
  Status err;
281
16
  return process.ReadSignedIntegerFromMemory(base_offset_addr, base_offset_size,
282
16
                                             INT64_MAX, err);
283
16
}
284
285
static bool GetVBaseBitOffset(VTableContextBase &vtable_ctx,
286
                              ValueObject &valobj,
287
                              const ASTRecordLayout &record_layout,
288
                              const CXXRecordDecl *cxx_record_decl,
289
                              const CXXRecordDecl *base_class_decl,
290
16
                              int32_t &bit_offset) {
291
16
  ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
292
16
  Process *process = exe_ctx.GetProcessPtr();
293
16
  if (!process)
294
0
    return false;
295
296
16
  lldb::addr_t vtable_ptr =
297
16
      GetVTableAddress(*process, vtable_ctx, valobj, record_layout);
298
16
  if (vtable_ptr == LLDB_INVALID_ADDRESS)
299
0
    return false;
300
301
16
  auto base_offset = ReadVBaseOffsetFromVTable(
302
16
      *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
303
16
  if (base_offset == INT64_MAX)
304
0
    return false;
305
306
16
  bit_offset = base_offset * 8;
307
308
16
  return true;
309
16
}
310
311
typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, TypeSystemClang *>
312
    ClangASTMap;
313
314
5.96M
static ClangASTMap &GetASTMap() {
315
5.96M
  static ClangASTMap *g_map_ptr = nullptr;
316
5.96M
  static llvm::once_flag g_once_flag;
317
5.96M
  llvm::call_once(g_once_flag, []() {
318
920
    g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins
319
920
  });
320
5.96M
  return *g_map_ptr;
321
5.96M
}
322
323
TypePayloadClang::TypePayloadClang(OptionalClangModuleID owning_module,
324
                                   bool is_complete_objc_class)
325
70.8k
    : m_payload(owning_module.GetValue()) {
326
70.8k
  SetIsCompleteObjCClass(is_complete_objc_class);
327
70.8k
}
328
329
0
void TypePayloadClang::SetOwningModule(OptionalClangModuleID id) {
330
0
  assert(id.GetValue() < ObjCClassBit);
331
0
  bool is_complete = IsCompleteObjCClass();
332
0
  m_payload = id.GetValue();
333
0
  SetIsCompleteObjCClass(is_complete);
334
0
}
335
336
static void SetMemberOwningModule(clang::Decl *member,
337
76.8k
                                  const clang::Decl *parent) {
338
76.8k
  if (!member || !parent)
339
0
    return;
340
341
76.8k
  OptionalClangModuleID id(parent->getOwningModuleID());
342
76.8k
  if (!id.HasValue())
343
50.8k
    return;
344
345
25.9k
  member->setFromASTFile();
346
25.9k
  member->setOwningModuleID(id.GetValue());
347
25.9k
  member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
348
25.9k
  if (llvm::isa<clang::NamedDecl>(member))
349
25.9k
    if (auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
350
25.9k
      dc->setHasExternalVisibleStorage(true);
351
      // This triggers ExternalASTSource::FindExternalVisibleDeclsByName() to be
352
      // called when searching for members.
353
25.9k
      dc->setHasExternalLexicalStorage(true);
354
25.9k
    }
355
25.9k
}
356
357
char TypeSystemClang::ID;
358
359
bool TypeSystemClang::IsOperator(llvm::StringRef name,
360
56.8k
                                 clang::OverloadedOperatorKind &op_kind) {
361
  // All operators have to start with "operator".
362
56.8k
  if (!name.consume_front("operator"))
363
52.1k
    return false;
364
365
  // Remember if there was a space after "operator". This is necessary to
366
  // check for collisions with strangely named functions like "operatorint()".
367
4.65k
  bool space_after_operator = name.consume_front(" ");
368
369
4.65k
  op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
370
4.65k
                .Case("+", clang::OO_Plus)
371
4.65k
                .Case("+=", clang::OO_PlusEqual)
372
4.65k
                .Case("++", clang::OO_PlusPlus)
373
4.65k
                .Case("-", clang::OO_Minus)
374
4.65k
                .Case("-=", clang::OO_MinusEqual)
375
4.65k
                .Case("--", clang::OO_MinusMinus)
376
4.65k
                .Case("->", clang::OO_Arrow)
377
4.65k
                .Case("->*", clang::OO_ArrowStar)
378
4.65k
                .Case("*", clang::OO_Star)
379
4.65k
                .Case("*=", clang::OO_StarEqual)
380
4.65k
                .Case("/", clang::OO_Slash)
381
4.65k
                .Case("/=", clang::OO_SlashEqual)
382
4.65k
                .Case("%", clang::OO_Percent)
383
4.65k
                .Case("%=", clang::OO_PercentEqual)
384
4.65k
                .Case("^", clang::OO_Caret)
385
4.65k
                .Case("^=", clang::OO_CaretEqual)
386
4.65k
                .Case("&", clang::OO_Amp)
387
4.65k
                .Case("&=", clang::OO_AmpEqual)
388
4.65k
                .Case("&&", clang::OO_AmpAmp)
389
4.65k
                .Case("|", clang::OO_Pipe)
390
4.65k
                .Case("|=", clang::OO_PipeEqual)
391
4.65k
                .Case("||", clang::OO_PipePipe)
392
4.65k
                .Case("~", clang::OO_Tilde)
393
4.65k
                .Case("!", clang::OO_Exclaim)
394
4.65k
                .Case("!=", clang::OO_ExclaimEqual)
395
4.65k
                .Case("=", clang::OO_Equal)
396
4.65k
                .Case("==", clang::OO_EqualEqual)
397
4.65k
                .Case("<", clang::OO_Less)
398
4.65k
                .Case("<<", clang::OO_LessLess)
399
4.65k
                .Case("<<=", clang::OO_LessLessEqual)
400
4.65k
                .Case("<=", clang::OO_LessEqual)
401
4.65k
                .Case(">", clang::OO_Greater)
402
4.65k
                .Case(">>", clang::OO_GreaterGreater)
403
4.65k
                .Case(">>=", clang::OO_GreaterGreaterEqual)
404
4.65k
                .Case(">=", clang::OO_GreaterEqual)
405
4.65k
                .Case("()", clang::OO_Call)
406
4.65k
                .Case("[]", clang::OO_Subscript)
407
4.65k
                .Case(",", clang::OO_Comma)
408
4.65k
                .Default(clang::NUM_OVERLOADED_OPERATORS);
409
410
  // We found a fitting operator, so we can exit now.
411
4.65k
  if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
412
4.31k
    return true;
413
414
  // After the "operator " or "operator" part is something unknown. This means
415
  // it's either one of the named operators (new/delete), a conversion operator
416
  // (e.g. operator bool) or a function which name starts with "operator"
417
  // (e.g. void operatorbool).
418
419
  // If it's a function that starts with operator it can't have a space after
420
  // "operator" because identifiers can't contain spaces.
421
  // E.g. "operator int" (conversion operator)
422
  //  vs. "operatorint" (function with colliding name).
423
344
  if (!space_after_operator)
424
24
    return false; // not an operator.
425
426
  // Now the operator is either one of the named operators or a conversion
427
  // operator.
428
320
  op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
429
320
                .Case("new", clang::OO_New)
430
320
                .Case("new[]", clang::OO_Array_New)
431
320
                .Case("delete", clang::OO_Delete)
432
320
                .Case("delete[]", clang::OO_Array_Delete)
433
                // conversion operators hit this case.
434
320
                .Default(clang::NUM_OVERLOADED_OPERATORS);
435
436
320
  return true;
437
344
}
438
439
clang::AccessSpecifier
440
79.4k
TypeSystemClang::ConvertAccessTypeToAccessSpecifier(AccessType access) {
441
79.4k
  switch (access) {
442
1
  default:
443
1
    break;
444
1
  case eAccessNone:
445
1
    return AS_none;
446
73.5k
  case eAccessPublic:
447
73.5k
    return AS_public;
448
3.56k
  case eAccessPrivate:
449
3.56k
    return AS_private;
450
2.35k
  case eAccessProtected:
451
2.35k
    return AS_protected;
452
79.4k
  }
453
1
  return AS_none;
454
79.4k
}
455
456
7.76k
static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) {
457
  // FIXME: Cleanup per-file based stuff.
458
459
  // Set some properties which depend solely on the input kind; it would be
460
  // nice to move these to the language standard, and have the driver resolve
461
  // the input kind + language standard.
462
7.76k
  if (IK.getLanguage() == clang::Language::Asm) {
463
0
    Opts.AsmPreprocessor = 1;
464
7.76k
  } else if (IK.isObjectiveC()) {
465
7.76k
    Opts.ObjC = 1;
466
7.76k
  }
467
468
7.76k
  LangStandard::Kind LangStd = LangStandard::lang_unspecified;
469
470
7.76k
  if (LangStd == LangStandard::lang_unspecified) {
471
    // Based on the base language, pick one.
472
7.76k
    switch (IK.getLanguage()) {
473
0
    case clang::Language::Unknown:
474
0
    case clang::Language::LLVM_IR:
475
0
    case clang::Language::RenderScript:
476
0
      llvm_unreachable("Invalid input kind!");
477
0
    case clang::Language::OpenCL:
478
0
      LangStd = LangStandard::lang_opencl10;
479
0
      break;
480
0
    case clang::Language::OpenCLCXX:
481
0
      LangStd = LangStandard::lang_openclcpp10;
482
0
      break;
483
0
    case clang::Language::CUDA:
484
0
      LangStd = LangStandard::lang_cuda;
485
0
      break;
486
0
    case clang::Language::Asm:
487
0
    case clang::Language::C:
488
0
    case clang::Language::ObjC:
489
0
      LangStd = LangStandard::lang_gnu99;
490
0
      break;
491
0
    case clang::Language::CXX:
492
7.76k
    case clang::Language::ObjCXX:
493
7.76k
      LangStd = LangStandard::lang_gnucxx98;
494
7.76k
      break;
495
0
    case clang::Language::HIP:
496
0
      LangStd = LangStandard::lang_hip;
497
0
      break;
498
7.76k
    }
499
7.76k
  }
500
501
7.76k
  const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
502
7.76k
  Opts.LineComment = Std.hasLineComments();
503
7.76k
  Opts.C99 = Std.isC99();
504
7.76k
  Opts.CPlusPlus = Std.isCPlusPlus();
505
7.76k
  Opts.CPlusPlus11 = Std.isCPlusPlus11();
506
7.76k
  Opts.Digraphs = Std.hasDigraphs();
507
7.76k
  Opts.GNUMode = Std.isGNUMode();
508
7.76k
  Opts.GNUInline = !Std.isC99();
509
7.76k
  Opts.HexFloats = Std.hasHexFloats();
510
7.76k
  Opts.ImplicitInt = Std.hasImplicitInt();
511
512
7.76k
  Opts.WChar = true;
513
514
  // OpenCL has some additional defaults.
515
7.76k
  if (LangStd == LangStandard::lang_opencl10) {
516
0
    Opts.OpenCL = 1;
517
0
    Opts.AltiVec = 1;
518
0
    Opts.CXXOperatorNames = 1;
519
0
    Opts.setLaxVectorConversions(LangOptions::LaxVectorConversionKind::All);
520
0
  }
521
522
  // OpenCL and C++ both have bool, true, false keywords.
523
7.76k
  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
524
525
7.76k
  Opts.setValueVisibilityMode(DefaultVisibility);
526
527
  // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs is
528
  // specified, or -std is set to a conforming mode.
529
7.76k
  Opts.Trigraphs = !Opts.GNUMode;
530
7.76k
  Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault();
531
7.76k
  Opts.OptimizeSize = 0;
532
533
  // FIXME: Eliminate this dependency.
534
  //    unsigned Opt =
535
  //    Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags);
536
  //    Opts.Optimize = Opt != 0;
537
7.76k
  unsigned Opt = 0;
538
539
  // This is the __NO_INLINE__ define, which just depends on things like the
540
  // optimization level and -fno-inline, not actually whether the backend has
541
  // inlining enabled.
542
  //
543
  // FIXME: This is affected by other options (-fno-inline).
544
7.76k
  Opts.NoInlineDefine = !Opt;
545
546
  // This is needed to allocate the extra space for the owning module
547
  // on each decl.
548
7.76k
  Opts.ModulesLocalVisibility = 1;
549
7.76k
}
550
551
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
552
7.76k
                                 llvm::Triple target_triple) {
553
7.76k
  m_display_name = name.str();
554
7.76k
  if (!target_triple.str().empty())
555
7.76k
    SetTargetTriple(target_triple.str());
556
  // The caller didn't pass an ASTContext so create a new one for this
557
  // TypeSystemClang.
558
7.76k
  CreateASTContext();
559
7.76k
}
560
561
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
562
16.6k
                                 ASTContext &existing_ctxt) {
563
16.6k
  m_display_name = name.str();
564
16.6k
  SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
565
566
16.6k
  m_ast_up.reset(&existing_ctxt);
567
16.6k
  GetASTMap().Insert(&existing_ctxt, this);
568
16.6k
}
569
570
// Destructor
571
24.2k
TypeSystemClang::~TypeSystemClang() { Finalize(); }
572
573
lldb::TypeSystemSP TypeSystemClang::CreateInstance(lldb::LanguageType language,
574
                                                   lldb_private::Module *module,
575
5.40k
                                                   Target *target) {
576
5.40k
  if (!TypeSystemClangSupportsLanguage(language))
577
1
    return lldb::TypeSystemSP();
578
5.40k
  ArchSpec arch;
579
5.40k
  if (module)
580
2.93k
    arch = module->GetArchitecture();
581
2.46k
  else if (target)
582
2.46k
    arch = target->GetArchitecture();
583
584
5.40k
  if (!arch.IsValid())
585
0
    return lldb::TypeSystemSP();
586
587
5.40k
  llvm::Triple triple = arch.GetTriple();
588
  // LLVM wants this to be set to iOS or MacOSX; if we're working on
589
  // a bare-boards type image, change the triple for llvm's benefit.
590
5.40k
  if (triple.getVendor() == llvm::Triple::Apple &&
591
5.40k
      
triple.getOS() == llvm::Triple::UnknownOS5.30k
) {
592
2
    if (triple.getArch() == llvm::Triple::arm ||
593
2
        triple.getArch() == llvm::Triple::aarch64 ||
594
2
        triple.getArch() == llvm::Triple::aarch64_32 ||
595
2
        triple.getArch() == llvm::Triple::thumb) {
596
0
      triple.setOS(llvm::Triple::IOS);
597
2
    } else {
598
2
      triple.setOS(llvm::Triple::MacOSX);
599
2
    }
600
2
  }
601
602
5.40k
  if (module) {
603
2.93k
    std::string ast_name =
604
2.93k
        "ASTContext for '" + module->GetFileSpec().GetPath() + "'";
605
2.93k
    return std::make_shared<TypeSystemClang>(ast_name, triple);
606
2.93k
  } else 
if (2.46k
target2.46k
&&
target->IsValid()2.46k
)
607
2.46k
    return std::make_shared<ScratchTypeSystemClang>(*target, triple);
608
0
  return lldb::TypeSystemSP();
609
5.40k
}
610
611
3.47k
LanguageSet TypeSystemClang::GetSupportedLanguagesForTypes() {
612
3.47k
  LanguageSet languages;
613
3.47k
  languages.Insert(lldb::eLanguageTypeC89);
614
3.47k
  languages.Insert(lldb::eLanguageTypeC);
615
3.47k
  languages.Insert(lldb::eLanguageTypeC11);
616
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus);
617
3.47k
  languages.Insert(lldb::eLanguageTypeC99);
618
3.47k
  languages.Insert(lldb::eLanguageTypeObjC);
619
3.47k
  languages.Insert(lldb::eLanguageTypeObjC_plus_plus);
620
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_03);
621
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_11);
622
3.47k
  languages.Insert(lldb::eLanguageTypeC11);
623
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_14);
624
3.47k
  return languages;
625
3.47k
}
626
627
3.47k
LanguageSet TypeSystemClang::GetSupportedLanguagesForExpressions() {
628
3.47k
  LanguageSet languages;
629
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus);
630
3.47k
  languages.Insert(lldb::eLanguageTypeObjC_plus_plus);
631
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_03);
632
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_11);
633
3.47k
  languages.Insert(lldb::eLanguageTypeC_plus_plus_14);
634
3.47k
  return languages;
635
3.47k
}
636
637
3.47k
void TypeSystemClang::Initialize() {
638
3.47k
  PluginManager::RegisterPlugin(
639
3.47k
      GetPluginNameStatic(), "clang base AST context plug-in", CreateInstance,
640
3.47k
      GetSupportedLanguagesForTypes(), GetSupportedLanguagesForExpressions());
641
3.47k
}
642
643
3.46k
void TypeSystemClang::Terminate() {
644
3.46k
  PluginManager::UnregisterPlugin(CreateInstance);
645
3.46k
}
646
647
26.6k
void TypeSystemClang::Finalize() {
648
26.6k
  assert(m_ast_up);
649
0
  GetASTMap().Erase(m_ast_up.get());
650
26.6k
  if (!m_ast_owned)
651
16.5k
    m_ast_up.release();
652
653
26.6k
  m_builtins_up.reset();
654
26.6k
  m_selector_table_up.reset();
655
26.6k
  m_identifier_table_up.reset();
656
26.6k
  m_target_info_up.reset();
657
26.6k
  m_target_options_rp.reset();
658
26.6k
  m_diagnostics_engine_up.reset();
659
26.6k
  m_source_manager_up.reset();
660
26.6k
  m_language_options_up.reset();
661
26.6k
}
662
663
1.57k
void TypeSystemClang::setSema(Sema *s) {
664
  // Ensure that the new sema actually belongs to our ASTContext.
665
1.57k
  assert(s == nullptr || &s->getASTContext() == m_ast_up.get());
666
0
  m_sema = s;
667
1.57k
}
668
669
7.76k
const char *TypeSystemClang::GetTargetTriple() {
670
7.76k
  return m_target_triple.c_str();
671
7.76k
}
672
673
24.4k
void TypeSystemClang::SetTargetTriple(llvm::StringRef target_triple) {
674
24.4k
  m_target_triple = target_triple.str();
675
24.4k
}
676
677
void TypeSystemClang::SetExternalSource(
678
10.3k
    llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
679
10.3k
  ASTContext &ast = getASTContext();
680
10.3k
  ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(true);
681
10.3k
  ast.setExternalSource(ast_source_up);
682
10.3k
}
683
684
3.99M
ASTContext &TypeSystemClang::getASTContext() {
685
3.99M
  assert(m_ast_up);
686
0
  return *m_ast_up;
687
3.99M
}
688
689
class NullDiagnosticConsumer : public DiagnosticConsumer {
690
public:
691
7.76k
  NullDiagnosticConsumer() {
692
7.76k
    m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
693
7.76k
  }
694
695
  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
696
584k
                        const clang::Diagnostic &info) override {
697
584k
    if (m_log) {
698
0
      llvm::SmallVector<char, 32> diag_str(10);
699
0
      info.FormatDiagnostic(diag_str);
700
0
      diag_str.push_back('\0');
701
0
      LLDB_LOGF(m_log, "Compiler diagnostic: %s\n", diag_str.data());
702
0
    }
703
584k
  }
704
705
0
  DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
706
0
    return new NullDiagnosticConsumer();
707
0
  }
708
709
private:
710
  Log *m_log;
711
};
712
713
7.76k
void TypeSystemClang::CreateASTContext() {
714
7.76k
  assert(!m_ast_up);
715
0
  m_ast_owned = true;
716
717
7.76k
  m_language_options_up = std::make_unique<LangOptions>();
718
7.76k
  ParseLangArgs(*m_language_options_up, clang::Language::ObjCXX,
719
7.76k
                GetTargetTriple());
720
721
7.76k
  m_identifier_table_up =
722
7.76k
      std::make_unique<IdentifierTable>(*m_language_options_up, nullptr);
723
7.76k
  m_builtins_up = std::make_unique<Builtin::Context>();
724
725
7.76k
  m_selector_table_up = std::make_unique<SelectorTable>();
726
727
7.76k
  clang::FileSystemOptions file_system_options;
728
7.76k
  m_file_manager_up = std::make_unique<clang::FileManager>(
729
7.76k
      file_system_options, FileSystem::Instance().GetVirtualFileSystem());
730
731
7.76k
  llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs());
732
7.76k
  m_diagnostics_engine_up =
733
7.76k
      std::make_unique<DiagnosticsEngine>(diag_id_sp, new DiagnosticOptions());
734
735
7.76k
  m_source_manager_up = std::make_unique<clang::SourceManager>(
736
7.76k
      *m_diagnostics_engine_up, *m_file_manager_up);
737
7.76k
  m_ast_up = std::make_unique<ASTContext>(
738
7.76k
      *m_language_options_up, *m_source_manager_up, *m_identifier_table_up,
739
7.76k
      *m_selector_table_up, *m_builtins_up, TU_Complete);
740
741
7.76k
  m_diagnostic_consumer_up = std::make_unique<NullDiagnosticConsumer>();
742
7.76k
  m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
743
744
  // This can be NULL if we don't know anything about the architecture or if
745
  // the target for an architecture isn't enabled in the llvm/clang that we
746
  // built
747
7.76k
  TargetInfo *target_info = getTargetInfo();
748
7.76k
  if (target_info)
749
7.76k
    m_ast_up->InitBuiltinTypes(*target_info);
750
751
7.76k
  GetASTMap().Insert(m_ast_up.get(), this);
752
753
7.76k
  llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
754
7.76k
      new ClangExternalASTSourceCallbacks(*this));
755
7.76k
  SetExternalSource(ast_source_up);
756
7.76k
}
757
758
5.91M
TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) {
759
5.91M
  TypeSystemClang *clang_ast = GetASTMap().Lookup(ast);
760
5.91M
  return clang_ast;
761
5.91M
}
762
763
36
clang::MangleContext *TypeSystemClang::getMangleContext() {
764
36
  if (m_mangle_ctx_up == nullptr)
765
3
    m_mangle_ctx_up.reset(getASTContext().createMangleContext());
766
36
  return m_mangle_ctx_up.get();
767
36
}
768
769
7.76k
std::shared_ptr<clang::TargetOptions> &TypeSystemClang::getTargetOptions() {
770
7.76k
  if (m_target_options_rp == nullptr && !m_target_triple.empty()) {
771
7.76k
    m_target_options_rp = std::make_shared<clang::TargetOptions>();
772
7.76k
    if (m_target_options_rp != nullptr)
773
7.76k
      m_target_options_rp->Triple = m_target_triple;
774
7.76k
  }
775
7.76k
  return m_target_options_rp;
776
7.76k
}
777
778
7.79k
TargetInfo *TypeSystemClang::getTargetInfo() {
779
  // target_triple should be something like "x86_64-apple-macosx"
780
7.79k
  if (m_target_info_up == nullptr && 
!m_target_triple.empty()7.76k
)
781
7.76k
    m_target_info_up.reset(TargetInfo::CreateTargetInfo(
782
7.76k
        getASTContext().getDiagnostics(), getTargetOptions()));
783
7.79k
  return m_target_info_up.get();
784
7.79k
}
785
786
#pragma mark Basic Types
787
788
static inline bool QualTypeMatchesBitSize(const uint64_t bit_size,
789
46.6k
                                          ASTContext &ast, QualType qual_type) {
790
46.6k
  uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
791
46.6k
  return qual_type_bit_size == bit_size;
792
46.6k
}
793
794
CompilerType
795
TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
796
14.0k
                                                     size_t bit_size) {
797
14.0k
  ASTContext &ast = getASTContext();
798
14.0k
  switch (encoding) {
799
0
  case eEncodingInvalid:
800
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
801
0
      return GetType(ast.VoidPtrTy);
802
0
    break;
803
804
13.5k
  case eEncodingUint:
805
13.5k
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
806
184
      return GetType(ast.UnsignedCharTy);
807
13.3k
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
808
1.39k
      return GetType(ast.UnsignedShortTy);
809
11.9k
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
810
10.3k
      return GetType(ast.UnsignedIntTy);
811
1.66k
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
812
1.65k
      return GetType(ast.UnsignedLongTy);
813
8
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
814
0
      return GetType(ast.UnsignedLongLongTy);
815
8
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
816
7
      return GetType(ast.UnsignedInt128Ty);
817
1
    break;
818
819
112
  case eEncodingSint:
820
112
    if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
821
1
      return GetType(ast.SignedCharTy);
822
111
    if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
823
7
      return GetType(ast.ShortTy);
824
104
    if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
825
81
      return GetType(ast.IntTy);
826
23
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
827
22
      return GetType(ast.LongTy);
828
1
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
829
0
      return GetType(ast.LongLongTy);
830
1
    if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
831
1
      return GetType(ast.Int128Ty);
832
0
    break;
833
834
20
  case eEncodingIEEE754:
835
20
    if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
836
19
      return GetType(ast.FloatTy);
837
1
    if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
838
1
      return GetType(ast.DoubleTy);
839
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
840
0
      return GetType(ast.LongDoubleTy);
841
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
842
0
      return GetType(ast.HalfTy);
843
0
    break;
844
845
363
  case eEncodingVector:
846
    // Sanity check that bit_size is a multiple of 8's.
847
363
    if (bit_size && !(bit_size & 0x7u))
848
363
      return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
849
0
    break;
850
14.0k
  }
851
852
1
  return CompilerType();
853
14.0k
}
854
855
lldb::BasicType
856
37
TypeSystemClang::GetBasicTypeEnumeration(ConstString name) {
857
37
  if (name) {
858
37
    typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
859
37
    static TypeNameToBasicTypeMap g_type_map;
860
37
    static llvm::once_flag g_once_flag;
861
37
    llvm::call_once(g_once_flag, []() {
862
      // "void"
863
3
      g_type_map.Append(ConstString("void"), eBasicTypeVoid);
864
865
      // "char"
866
3
      g_type_map.Append(ConstString("char"), eBasicTypeChar);
867
3
      g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar);
868
3
      g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar);
869
3
      g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar);
870
3
      g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar);
871
3
      g_type_map.Append(ConstString("unsigned wchar_t"),
872
3
                        eBasicTypeUnsignedWChar);
873
      // "short"
874
3
      g_type_map.Append(ConstString("short"), eBasicTypeShort);
875
3
      g_type_map.Append(ConstString("short int"), eBasicTypeShort);
876
3
      g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort);
877
3
      g_type_map.Append(ConstString("unsigned short int"),
878
3
                        eBasicTypeUnsignedShort);
879
880
      // "int"
881
3
      g_type_map.Append(ConstString("int"), eBasicTypeInt);
882
3
      g_type_map.Append(ConstString("signed int"), eBasicTypeInt);
883
3
      g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt);
884
3
      g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt);
885
886
      // "long"
887
3
      g_type_map.Append(ConstString("long"), eBasicTypeLong);
888
3
      g_type_map.Append(ConstString("long int"), eBasicTypeLong);
889
3
      g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong);
890
3
      g_type_map.Append(ConstString("unsigned long int"),
891
3
                        eBasicTypeUnsignedLong);
892
893
      // "long long"
894
3
      g_type_map.Append(ConstString("long long"), eBasicTypeLongLong);
895
3
      g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong);
896
3
      g_type_map.Append(ConstString("unsigned long long"),
897
3
                        eBasicTypeUnsignedLongLong);
898
3
      g_type_map.Append(ConstString("unsigned long long int"),
899
3
                        eBasicTypeUnsignedLongLong);
900
901
      // "int128"
902
3
      g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128);
903
3
      g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128);
904
905
      // Miscellaneous
906
3
      g_type_map.Append(ConstString("bool"), eBasicTypeBool);
907
3
      g_type_map.Append(ConstString("float"), eBasicTypeFloat);
908
3
      g_type_map.Append(ConstString("double"), eBasicTypeDouble);
909
3
      g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble);
910
3
      g_type_map.Append(ConstString("id"), eBasicTypeObjCID);
911
3
      g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel);
912
3
      g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr);
913
3
      g_type_map.Sort();
914
3
    });
915
916
37
    return g_type_map.Find(name, eBasicTypeInvalid);
917
37
  }
918
0
  return eBasicTypeInvalid;
919
37
}
920
921
2.99k
uint32_t TypeSystemClang::GetPointerByteSize() {
922
2.99k
  if (m_pointer_byte_size == 0)
923
206
    if (auto size = GetBasicType(lldb::eBasicTypeVoid)
924
206
                        .GetPointerType()
925
206
                        .GetByteSize(nullptr))
926
206
      m_pointer_byte_size = *size;
927
2.99k
  return m_pointer_byte_size;
928
2.99k
}
929
930
35.5k
CompilerType TypeSystemClang::GetBasicType(lldb::BasicType basic_type) {
931
35.5k
  clang::ASTContext &ast = getASTContext();
932
933
35.5k
  lldb::opaque_compiler_type_t clang_type =
934
35.5k
      GetOpaqueCompilerType(&ast, basic_type);
935
936
35.5k
  if (clang_type)
937
35.5k
    return CompilerType(this, clang_type);
938
4
  return CompilerType();
939
35.5k
}
940
941
CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
942
5.66k
    llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
943
5.66k
  ASTContext &ast = getASTContext();
944
945
5.66k
  switch (dw_ate) {
946
3
  default:
947
3
    break;
948
949
3
  case DW_ATE_address:
950
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
951
0
      return GetType(ast.VoidPtrTy);
952
0
    break;
953
954
289
  case DW_ATE_boolean:
955
289
    if (QualTypeMatchesBitSize(bit_size, ast, ast.BoolTy))
956
289
      return GetType(ast.BoolTy);
957
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
958
0
      return GetType(ast.UnsignedCharTy);
959
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
960
0
      return GetType(ast.UnsignedShortTy);
961
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
962
0
      return GetType(ast.UnsignedIntTy);
963
0
    break;
964
965
4
  case DW_ATE_lo_user:
966
    // This has been seen to mean DW_AT_complex_integer
967
4
    if (type_name.contains("complex")) {
968
4
      CompilerType complex_int_clang_type =
969
4
          GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
970
4
                                                   bit_size / 2);
971
4
      return GetType(
972
4
          ast.getComplexType(ClangUtil::GetQualType(complex_int_clang_type)));
973
4
    }
974
0
    break;
975
976
6
  case DW_ATE_complex_float: {
977
6
    CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
978
6
    if (QualTypeMatchesBitSize(bit_size, ast, FloatComplexTy))
979
2
      return GetType(FloatComplexTy);
980
981
4
    CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
982
4
    if (QualTypeMatchesBitSize(bit_size, ast, DoubleComplexTy))
983
2
      return GetType(DoubleComplexTy);
984
985
2
    CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
986
2
    if (QualTypeMatchesBitSize(bit_size, ast, LongDoubleComplexTy))
987
2
      return GetType(LongDoubleComplexTy);
988
989
0
    CompilerType complex_float_clang_type =
990
0
        GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
991
0
                                                 bit_size / 2);
992
0
    return GetType(
993
0
        ast.getComplexType(ClangUtil::GetQualType(complex_float_clang_type)));
994
2
  }
995
996
356
  case DW_ATE_float:
997
356
    if (type_name == "float" &&
998
356
        
QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy)121
)
999
121
      return GetType(ast.FloatTy);
1000
235
    if (type_name == "double" &&
1001
235
        
QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy)232
)
1002
232
      return GetType(ast.DoubleTy);
1003
3
    if (type_name == "long double" &&
1004
3
        QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
1005
3
      return GetType(ast.LongDoubleTy);
1006
    // Fall back to not requiring a name match
1007
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
1008
0
      return GetType(ast.FloatTy);
1009
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
1010
0
      return GetType(ast.DoubleTy);
1011
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
1012
0
      return GetType(ast.LongDoubleTy);
1013
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
1014
0
      return GetType(ast.HalfTy);
1015
0
    break;
1016
1017
2.78k
  case DW_ATE_signed:
1018
2.78k
    if (!type_name.empty()) {
1019
2.78k
      if (type_name == "wchar_t" &&
1020
2.78k
          
QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)14
&&
1021
2.78k
          
(14
getTargetInfo()14
&&
1022
14
           TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
1023
14
        return GetType(ast.WCharTy);
1024
2.77k
      if (type_name == "void" &&
1025
2.77k
          
QualTypeMatchesBitSize(bit_size, ast, ast.VoidTy)0
)
1026
0
        return GetType(ast.VoidTy);
1027
2.77k
      if (type_name.contains("long long") &&
1028
2.77k
          
QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy)61
)
1029
61
        return GetType(ast.LongLongTy);
1030
2.70k
      if (type_name.contains("long") &&
1031
2.70k
          
QualTypeMatchesBitSize(bit_size, ast, ast.LongTy)178
)
1032
178
        return GetType(ast.LongTy);
1033
2.53k
      if (type_name.contains("short") &&
1034
2.53k
          
QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy)82
)
1035
82
        return GetType(ast.ShortTy);
1036
2.44k
      if (type_name.contains("char")) {
1037
0
        if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1038
0
          return GetType(ast.CharTy);
1039
0
        if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
1040
0
          return GetType(ast.SignedCharTy);
1041
0
      }
1042
2.44k
      if (type_name.contains("int")) {
1043
2.44k
        if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
1044
2.44k
          return GetType(ast.IntTy);
1045
8
        if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
1046
6
          return GetType(ast.Int128Ty);
1047
8
      }
1048
2.44k
    }
1049
    // We weren't able to match up a type name, just search by size
1050
3
    if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1051
0
      return GetType(ast.CharTy);
1052
3
    if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
1053
0
      return GetType(ast.ShortTy);
1054
3
    if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
1055
1
      return GetType(ast.IntTy);
1056
2
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
1057
2
      return GetType(ast.LongTy);
1058
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
1059
0
      return GetType(ast.LongLongTy);
1060
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
1061
0
      return GetType(ast.Int128Ty);
1062
0
    break;
1063
1064
1.28k
  case DW_ATE_signed_char:
1065
1.28k
    if (ast.getLangOpts().CharIsSigned && type_name == "char") {
1066
1.21k
      if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1067
1.21k
        return GetType(ast.CharTy);
1068
1.21k
    }
1069
70
    if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
1070
70
      return GetType(ast.SignedCharTy);
1071
0
    break;
1072
1073
716
  case DW_ATE_unsigned:
1074
716
    if (!type_name.empty()) {
1075
716
      if (type_name == "wchar_t") {
1076
0
        if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) {
1077
0
          if (!(getTargetInfo() &&
1078
0
                TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
1079
0
            return GetType(ast.WCharTy);
1080
0
        }
1081
0
      }
1082
716
      if (type_name.contains("long long")) {
1083
54
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
1084
54
          return GetType(ast.UnsignedLongLongTy);
1085
662
      } else if (type_name.contains("long")) {
1086
361
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
1087
361
          return GetType(ast.UnsignedLongTy);
1088
361
      } else 
if (301
type_name.contains("short")301
) {
1089
72
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1090
72
          return GetType(ast.UnsignedShortTy);
1091
229
      } else if (type_name.contains("char")) {
1092
0
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1093
0
          return GetType(ast.UnsignedCharTy);
1094
229
      } else if (type_name.contains("int")) {
1095
229
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
1096
226
          return GetType(ast.UnsignedIntTy);
1097
3
        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
1098
3
          return GetType(ast.UnsignedInt128Ty);
1099
3
      }
1100
716
    }
1101
    // We weren't able to match up a type name, just search by size
1102
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1103
0
      return GetType(ast.UnsignedCharTy);
1104
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1105
0
      return GetType(ast.UnsignedShortTy);
1106
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
1107
0
      return GetType(ast.UnsignedIntTy);
1108
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
1109
0
      return GetType(ast.UnsignedLongTy);
1110
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
1111
0
      return GetType(ast.UnsignedLongLongTy);
1112
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
1113
0
      return GetType(ast.UnsignedInt128Ty);
1114
0
    break;
1115
1116
191
  case DW_ATE_unsigned_char:
1117
191
    if (!ast.getLangOpts().CharIsSigned && 
type_name == "char"5
) {
1118
5
      if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1119
5
        return GetType(ast.CharTy);
1120
5
    }
1121
186
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1122
186
      return GetType(ast.UnsignedCharTy);
1123
0
    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1124
0
      return GetType(ast.UnsignedShortTy);
1125
0
    break;
1126
1127
0
  case DW_ATE_imaginary_float:
1128
0
    break;
1129
1130
31
  case DW_ATE_UTF:
1131
31
    switch (bit_size) {
1132
7
    case 8:
1133
7
      return GetType(ast.Char8Ty);
1134
12
    case 16:
1135
12
      return GetType(ast.Char16Ty);
1136
12
    case 32:
1137
12
      return GetType(ast.Char32Ty);
1138
0
    default:
1139
0
      if (!type_name.empty()) {
1140
0
        if (type_name == "char16_t")
1141
0
          return GetType(ast.Char16Ty);
1142
0
        if (type_name == "char32_t")
1143
0
          return GetType(ast.Char32Ty);
1144
0
        if (type_name == "char8_t")
1145
0
          return GetType(ast.Char8Ty);
1146
0
      }
1147
31
    }
1148
0
    break;
1149
5.66k
  }
1150
1151
3
  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES);
1152
3
  LLDB_LOG(log,
1153
3
           "error: need to add support for DW_TAG_base_type '{0}' "
1154
3
           "encoded with DW_ATE = {1:x}, bit_size = {2}",
1155
3
           type_name, dw_ate, bit_size);
1156
3
  return CompilerType();
1157
5.66k
}
1158
1159
223
CompilerType TypeSystemClang::GetCStringType(bool is_const) {
1160
223
  ASTContext &ast = getASTContext();
1161
223
  QualType char_type(ast.CharTy);
1162
1163
223
  if (is_const)
1164
223
    char_type.addConst();
1165
1166
223
  return GetType(ast.getPointerType(char_type));
1167
223
}
1168
1169
bool TypeSystemClang::AreTypesSame(CompilerType type1, CompilerType type2,
1170
40
                                   bool ignore_qualifiers) {
1171
40
  TypeSystemClang *ast =
1172
40
      llvm::dyn_cast_or_null<TypeSystemClang>(type1.GetTypeSystem());
1173
40
  if (!ast || ast != type2.GetTypeSystem())
1174
12
    return false;
1175
1176
28
  if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType())
1177
0
    return true;
1178
1179
28
  QualType type1_qual = ClangUtil::GetQualType(type1);
1180
28
  QualType type2_qual = ClangUtil::GetQualType(type2);
1181
1182
28
  if (ignore_qualifiers) {
1183
0
    type1_qual = type1_qual.getUnqualifiedType();
1184
0
    type2_qual = type2_qual.getUnqualifiedType();
1185
0
  }
1186
1187
28
  return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1188
28
}
1189
1190
898
CompilerType TypeSystemClang::GetTypeForDecl(void *opaque_decl) {
1191
898
  if (!opaque_decl)
1192
0
    return CompilerType();
1193
1194
898
  clang::Decl *decl = static_cast<clang::Decl *>(opaque_decl);
1195
898
  if (auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1196
898
    return GetTypeForDecl(named_decl);
1197
0
  return CompilerType();
1198
898
}
1199
1200
225k
CompilerDeclContext TypeSystemClang::CreateDeclContext(DeclContext *ctx) {
1201
  // Check that the DeclContext actually belongs to this ASTContext.
1202
225k
  assert(&ctx->getParentASTContext() == &getASTContext());
1203
0
  return CompilerDeclContext(this, ctx);
1204
225k
}
1205
1206
898
CompilerType TypeSystemClang::GetTypeForDecl(clang::NamedDecl *decl) {
1207
898
  if (clang::ObjCInterfaceDecl *interface_decl =
1208
898
      llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1209
898
    return GetTypeForDecl(interface_decl);
1210
0
  if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1211
0
    return GetTypeForDecl(tag_decl);
1212
0
  return CompilerType();
1213
0
}
1214
1215
46.1k
CompilerType TypeSystemClang::GetTypeForDecl(TagDecl *decl) {
1216
46.1k
  return GetType(getASTContext().getTagDeclType(decl));
1217
46.1k
}
1218
1219
1.03k
CompilerType TypeSystemClang::GetTypeForDecl(ObjCInterfaceDecl *decl) {
1220
1.03k
  return GetType(getASTContext().getObjCInterfaceType(decl));
1221
1.03k
}
1222
1223
#pragma mark Structure, Unions, Classes
1224
1225
void TypeSystemClang::SetOwningModule(clang::Decl *decl,
1226
146k
                                      OptionalClangModuleID owning_module) {
1227
146k
  if (!decl || !owning_module.HasValue())
1228
95.1k
    return;
1229
1230
50.9k
  decl->setFromASTFile();
1231
50.9k
  decl->setOwningModuleID(owning_module.GetValue());
1232
50.9k
  decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1233
50.9k
}
1234
1235
OptionalClangModuleID
1236
TypeSystemClang::GetOrCreateClangModule(llvm::StringRef name,
1237
                                        OptionalClangModuleID parent,
1238
21.8k
                                        bool is_framework, bool is_explicit) {
1239
  // Get the external AST source which holds the modules.
1240
21.8k
  auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1241
21.8k
      getASTContext().getExternalSource());
1242
21.8k
  assert(ast_source && "external ast source was lost");
1243
21.8k
  if (!ast_source)
1244
0
    return {};
1245
1246
  // Lazily initialize the module map.
1247
21.8k
  if (!m_header_search_up) {
1248
557
    auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1249
557
    m_header_search_up = std::make_unique<clang::HeaderSearch>(
1250
557
        HSOpts, *m_source_manager_up, *m_diagnostics_engine_up,
1251
557
        *m_language_options_up, m_target_info_up.get());
1252
557
    m_module_map_up = std::make_unique<clang::ModuleMap>(
1253
557
        *m_source_manager_up, *m_diagnostics_engine_up, *m_language_options_up,
1254
557
        m_target_info_up.get(), *m_header_search_up);
1255
557
  }
1256
1257
  // Get or create the module context.
1258
21.8k
  bool created;
1259
21.8k
  clang::Module *module;
1260
21.8k
  auto parent_desc = ast_source->getSourceDescriptor(parent.GetValue());
1261
21.8k
  std::tie(module, created) = m_module_map_up->findOrCreateModule(
1262
21.8k
      name, parent_desc ? 
parent_desc->getModuleOrNull()13.9k
:
nullptr7.88k
,
1263
21.8k
      is_framework, is_explicit);
1264
21.8k
  if (!created)
1265
18.0k
    return ast_source->GetIDForModule(module);
1266
1267
3.80k
  return ast_source->RegisterModule(module);
1268
21.8k
}
1269
1270
CompilerType TypeSystemClang::CreateRecordType(
1271
    clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1272
    AccessType access_type, llvm::StringRef name, int kind,
1273
7.79k
    LanguageType language, ClangASTMetadata *metadata, bool exports_symbols) {
1274
7.79k
  ASTContext &ast = getASTContext();
1275
1276
7.79k
  if (decl_ctx == nullptr)
1277
2.42k
    decl_ctx = ast.getTranslationUnitDecl();
1278
1279
7.79k
  if (language == eLanguageTypeObjC ||
1280
7.79k
      
language == eLanguageTypeObjC_plus_plus6.53k
) {
1281
1.35k
    bool isForwardDecl = true;
1282
1.35k
    bool isInternal = false;
1283
1.35k
    return CreateObjCClass(name, decl_ctx, owning_module, isForwardDecl,
1284
1.35k
                           isInternal, metadata);
1285
1.35k
  }
1286
1287
  // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and
1288
  // we will need to update this code. I was told to currently always use the
1289
  // CXXRecordDecl class since we often don't know from debug information if
1290
  // something is struct or a class, so we default to always use the more
1291
  // complete definition just in case.
1292
1293
6.44k
  bool has_name = !name.empty();
1294
6.44k
  CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1295
6.44k
  decl->setTagKind(static_cast<TagDecl::TagKind>(kind));
1296
6.44k
  decl->setDeclContext(decl_ctx);
1297
6.44k
  if (has_name)
1298
5.86k
    decl->setDeclName(&ast.Idents.get(name));
1299
6.44k
  SetOwningModule(decl, owning_module);
1300
1301
6.44k
  if (!has_name) {
1302
    // In C++ a lambda is also represented as an unnamed class. This is
1303
    // different from an *anonymous class* that the user wrote:
1304
    //
1305
    // struct A {
1306
    //  // anonymous class (GNU/MSVC extension)
1307
    //  struct {
1308
    //    int x;
1309
    //  };
1310
    //  // unnamed class within a class
1311
    //  struct {
1312
    //    int y;
1313
    //  } B;
1314
    // };
1315
    //
1316
    // void f() {
1317
    //    // unammed class outside of a class
1318
    //    struct {
1319
    //      int z;
1320
    //    } C;
1321
    // }
1322
    //
1323
    // Anonymous classes is a GNU/MSVC extension that clang supports. It
1324
    // requires the anonymous class be embedded within a class. So the new
1325
    // heuristic verifies this condition.
1326
582
    if (isa<CXXRecordDecl>(decl_ctx) && 
exports_symbols278
)
1327
216
      decl->setAnonymousStructOrUnion(true);
1328
582
  }
1329
1330
6.44k
  if (metadata)
1331
4.00k
    SetMetadata(decl, *metadata);
1332
1333
6.44k
  if (access_type != eAccessNone)
1334
3.21k
    decl->setAccess(ConvertAccessTypeToAccessSpecifier(access_type));
1335
1336
6.44k
  if (decl_ctx)
1337
6.44k
    decl_ctx->addDecl(decl);
1338
1339
6.44k
  return GetType(ast.getTagDeclType(decl));
1340
7.79k
}
1341
1342
namespace {
1343
/// Returns true iff the given TemplateArgument should be represented as an
1344
/// NonTypeTemplateParmDecl in the AST.
1345
13.3k
bool IsValueParam(const clang::TemplateArgument &argument) {
1346
13.3k
  return argument.getKind() == TemplateArgument::Integral;
1347
13.3k
}
1348
1349
void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1350
                            ASTContext &ct,
1351
                            clang::AccessSpecifier previous_access,
1352
72.9k
                            clang::AccessSpecifier access_specifier) {
1353
72.9k
  if (!cxx_record_decl->isClass() && 
!cxx_record_decl->isStruct()19.9k
)
1354
953
    return;
1355
72.0k
  if (previous_access != access_specifier) {
1356
    // For struct, don't add AS_public if it's the first AccessSpecDecl.
1357
    // For class, don't add AS_private if it's the first AccessSpecDecl.
1358
9.13k
    if ((cxx_record_decl->isStruct() &&
1359
9.13k
         
previous_access == clang::AccessSpecifier::AS_none5.82k
&&
1360
9.13k
         
access_specifier == clang::AccessSpecifier::AS_public5.32k
) ||
1361
9.13k
        
(4.19k
cxx_record_decl->isClass()4.19k
&&
1362
4.19k
         
previous_access == clang::AccessSpecifier::AS_none3.31k
&&
1363
5.52k
         
access_specifier == clang::AccessSpecifier::AS_private2.24k
)) {
1364
5.52k
      return;
1365
5.52k
    }
1366
3.61k
    cxx_record_decl->addDecl(
1367
3.61k
        AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1368
3.61k
                               SourceLocation(), SourceLocation()));
1369
3.61k
  }
1370
72.0k
}
1371
} // namespace
1372
1373
static TemplateParameterList *CreateTemplateParameterList(
1374
    ASTContext &ast,
1375
    const TypeSystemClang::TemplateParameterInfos &template_param_infos,
1376
7.86k
    llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1377
7.86k
  const bool parameter_pack = false;
1378
7.86k
  const bool is_typename = false;
1379
7.86k
  const unsigned depth = 0;
1380
7.86k
  const size_t num_template_params = template_param_infos.args.size();
1381
7.86k
  DeclContext *const decl_context =
1382
7.86k
      ast.getTranslationUnitDecl(); // Is this the right decl context?,
1383
18.8k
  for (size_t i = 0; i < num_template_params; 
++i11.0k
) {
1384
11.0k
    const char *name = template_param_infos.names[i];
1385
1386
11.0k
    IdentifierInfo *identifier_info = nullptr;
1387
11.0k
    if (name && 
name[0]10.4k
)
1388
10.4k
      identifier_info = &ast.Idents.get(name);
1389
11.0k
    if (IsValueParam(template_param_infos.args[i])) {
1390
2.23k
      QualType template_param_type =
1391
2.23k
          template_param_infos.args[i].getIntegralType();
1392
2.23k
      template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1393
2.23k
          ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1394
2.23k
          identifier_info, template_param_type, parameter_pack,
1395
2.23k
          ast.getTrivialTypeSourceInfo(template_param_type)));
1396
8.78k
    } else {
1397
8.78k
      template_param_decls.push_back(TemplateTypeParmDecl::Create(
1398
8.78k
          ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1399
8.78k
          identifier_info, is_typename, parameter_pack));
1400
8.78k
    }
1401
11.0k
  }
1402
1403
7.86k
  if (template_param_infos.packed_args) {
1404
977
    IdentifierInfo *identifier_info = nullptr;
1405
977
    if (template_param_infos.pack_name && 
template_param_infos.pack_name[0]924
)
1406
924
      identifier_info = &ast.Idents.get(template_param_infos.pack_name);
1407
977
    const bool parameter_pack_true = true;
1408
1409
977
    if (!template_param_infos.packed_args->args.empty() &&
1410
977
        
IsValueParam(template_param_infos.packed_args->args[0])868
) {
1411
42
      QualType template_param_type =
1412
42
          template_param_infos.packed_args->args[0].getIntegralType();
1413
42
      template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1414
42
          ast, decl_context, SourceLocation(), SourceLocation(), depth,
1415
42
          num_template_params, identifier_info, template_param_type,
1416
42
          parameter_pack_true,
1417
42
          ast.getTrivialTypeSourceInfo(template_param_type)));
1418
935
    } else {
1419
935
      template_param_decls.push_back(TemplateTypeParmDecl::Create(
1420
935
          ast, decl_context, SourceLocation(), SourceLocation(), depth,
1421
935
          num_template_params, identifier_info, is_typename,
1422
935
          parameter_pack_true));
1423
935
    }
1424
977
  }
1425
7.86k
  clang::Expr *const requires_clause = nullptr; // TODO: Concepts
1426
7.86k
  TemplateParameterList *template_param_list = TemplateParameterList::Create(
1427
7.86k
      ast, SourceLocation(), SourceLocation(), template_param_decls,
1428
7.86k
      SourceLocation(), requires_clause);
1429
7.86k
  return template_param_list;
1430
7.86k
}
1431
1432
clang::FunctionTemplateDecl *TypeSystemClang::CreateFunctionTemplateDecl(
1433
    clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1434
    clang::FunctionDecl *func_decl,
1435
2.30k
    const TemplateParameterInfos &template_param_infos) {
1436
  //    /// Create a function template node.
1437
2.30k
  ASTContext &ast = getASTContext();
1438
1439
2.30k
  llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1440
2.30k
  TemplateParameterList *template_param_list = CreateTemplateParameterList(
1441
2.30k
      ast, template_param_infos, template_param_decls);
1442
2.30k
  FunctionTemplateDecl *func_tmpl_decl =
1443
2.30k
      FunctionTemplateDecl::CreateDeserialized(ast, 0);
1444
2.30k
  func_tmpl_decl->setDeclContext(decl_ctx);
1445
2.30k
  func_tmpl_decl->setLocation(func_decl->getLocation());
1446
2.30k
  func_tmpl_decl->setDeclName(func_decl->getDeclName());
1447
2.30k
  func_tmpl_decl->init(func_decl, template_param_list);
1448
2.30k
  SetOwningModule(func_tmpl_decl, owning_module);
1449
1450
2.30k
  for (size_t i = 0, template_param_decl_count = template_param_decls.size();
1451
5.69k
       i < template_param_decl_count; 
++i3.39k
) {
1452
    // TODO: verify which decl context we should put template_param_decls into..
1453
3.39k
    template_param_decls[i]->setDeclContext(func_decl);
1454
3.39k
  }
1455
  // Function templates inside a record need to have an access specifier.
1456
  // It doesn't matter what access specifier we give the template as LLDB
1457
  // anyway allows accessing everything inside a record.
1458
2.30k
  if (decl_ctx->isRecord())
1459
2.27k
    func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1460
1461
2.30k
  return func_tmpl_decl;
1462
2.30k
}
1463
1464
void TypeSystemClang::CreateFunctionTemplateSpecializationInfo(
1465
    FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1466
2.30k
    const TemplateParameterInfos &infos) {
1467
2.30k
  TemplateArgumentList *template_args_ptr =
1468
2.30k
      TemplateArgumentList::CreateCopy(func_decl->getASTContext(), infos.args);
1469
1470
2.30k
  func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1471
2.30k
                                               template_args_ptr, nullptr);
1472
2.30k
}
1473
1474
/// Returns true if the given template parameter can represent the given value.
1475
/// For example, `typename T` can represent `int` but not integral values such
1476
/// as `int I = 3`.
1477
static bool TemplateParameterAllowsValue(NamedDecl *param,
1478
4.72k
                                         const TemplateArgument &value) {
1479
4.72k
  if (llvm::isa<TemplateTypeParmDecl>(param)) {
1480
    // Compare the argument kind, i.e. ensure that <typename> != <int>.
1481
3.26k
    if (value.getKind() != TemplateArgument::Type)
1482
26
      return false;
1483
3.26k
  } else 
if (auto *1.45k
type_param1.45k
=
1484
1.45k
                 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1485
    // Compare the argument kind, i.e. ensure that <typename> != <int>.
1486
1.45k
    if (!IsValueParam(value))
1487
0
      return false;
1488
    // Compare the integral type, i.e. ensure that <int> != <char>.
1489
1.45k
    if (type_param->getType() != value.getIntegralType())
1490
4
      return false;
1491
1.45k
  } else {
1492
    // There is no way to create other parameter decls at the moment, so we
1493
    // can't reach this case during normal LLDB usage. Log that this happened
1494
    // and assert.
1495
0
    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
1496
0
    LLDB_LOG(log,
1497
0
             "Don't know how to compare template parameter to passed"
1498
0
             " value. Decl kind of parameter is: {0}",
1499
0
             param->getDeclKindName());
1500
0
    lldbassert(false && "Can't compare this TemplateParmDecl subclass");
1501
    // In release builds just fall back to marking the parameter as not
1502
    // accepting the value so that we don't try to fit an instantiation to a
1503
    // template that doesn't fit. E.g., avoid that `S<1>` is being connected to
1504
    // `template<typename T> struct S;`.
1505
0
    return false;
1506
0
  }
1507
4.69k
  return true;
1508
4.72k
}
1509
1510
/// Returns true if the given class template declaration could produce an
1511
/// instantiation with the specified values.
1512
/// For example, `<typename T>` allows the arguments `float`, but not for
1513
/// example `bool, float` or `3` (as an integer parameter value).
1514
static bool ClassTemplateAllowsToInstantiationArgs(
1515
    ClassTemplateDecl *class_template_decl,
1516
3.27k
    const TypeSystemClang::TemplateParameterInfos &instantiation_values) {
1517
1518
3.27k
  TemplateParameterList &params = *class_template_decl->getTemplateParameters();
1519
1520
  // Save some work by iterating only once over the found parameters and
1521
  // calculate the information related to parameter packs.
1522
1523
  // Contains the first pack parameter (or non if there are none).
1524
3.27k
  llvm::Optional<NamedDecl *> pack_parameter;
1525
  // Contains the number of non-pack parameters.
1526
3.27k
  size_t non_pack_params = params.size();
1527
8.35k
  for (size_t i = 0; i < params.size(); 
++i5.07k
) {
1528
5.23k
    NamedDecl *param = params.getParam(i);
1529
5.23k
    if (param->isParameterPack()) {
1530
161
      pack_parameter = param;
1531
161
      non_pack_params = i;
1532
161
      break;
1533
161
    }
1534
5.23k
  }
1535
1536
  // The found template needs to have compatible non-pack template arguments.
1537
  // E.g., ensure that <typename, typename> != <typename>.
1538
  // The pack parameters are compared later.
1539
3.27k
  if (non_pack_params != instantiation_values.args.size())
1540
249
    return false;
1541
1542
  // Ensure that <typename...> != <typename>.
1543
3.02k
  if (pack_parameter.hasValue() != instantiation_values.hasParameterPack())
1544
0
    return false;
1545
1546
  // Compare the first pack parameter that was found with the first pack
1547
  // parameter value. The special case of having an empty parameter pack value
1548
  // always fits to a pack parameter.
1549
  // E.g., ensure that <int...> != <typename...>.
1550
3.02k
  if (pack_parameter && 
!instantiation_values.packed_args->args.empty()155
&&
1551
3.02k
      !TemplateParameterAllowsValue(
1552
109
          *pack_parameter, instantiation_values.packed_args->args.front()))
1553
28
    return false;
1554
1555
  // Compare all the non-pack parameters now.
1556
  // E.g., ensure that <int> != <long>.
1557
4.61k
  
for (const auto pair : llvm::zip_first(instantiation_values.args, params))2.99k
{
1558
4.61k
    const TemplateArgument &passed_arg = std::get<0>(pair);
1559
4.61k
    NamedDecl *found_param = std::get<1>(pair);
1560
4.61k
    if (!TemplateParameterAllowsValue(found_param, passed_arg))
1561
2
      return false;
1562
4.61k
  }
1563
1564
2.99k
  return class_template_decl;
1565
2.99k
}
1566
1567
ClassTemplateDecl *TypeSystemClang::CreateClassTemplateDecl(
1568
    DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1569
    lldb::AccessType access_type, llvm::StringRef class_name, int kind,
1570
8.52k
    const TemplateParameterInfos &template_param_infos) {
1571
8.52k
  ASTContext &ast = getASTContext();
1572
1573
8.52k
  ClassTemplateDecl *class_template_decl = nullptr;
1574
8.52k
  if (decl_ctx == nullptr)
1575
0
    decl_ctx = ast.getTranslationUnitDecl();
1576
1577
8.52k
  IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1578
8.52k
  DeclarationName decl_name(&identifier_info);
1579
1580
  // Search the AST for an existing ClassTemplateDecl that could be reused.
1581
8.52k
  clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1582
8.52k
  for (NamedDecl *decl : result) {
1583
3.27k
    class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1584
3.27k
    if (!class_template_decl)
1585
0
      continue;
1586
    // The class template has to be able to represents the instantiation
1587
    // values we received. Without this we might end up putting an instantiation
1588
    // with arguments such as <int, int> to a template such as:
1589
    //     template<typename T> struct S;
1590
    // Connecting the instantiation to an incompatible template could cause
1591
    // problems later on.
1592
3.27k
    if (!ClassTemplateAllowsToInstantiationArgs(class_template_decl,
1593
3.27k
                                                template_param_infos))
1594
279
      continue;
1595
2.99k
    return class_template_decl;
1596
3.27k
  }
1597
1598
5.52k
  llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1599
1600
5.52k
  TemplateParameterList *template_param_list = CreateTemplateParameterList(
1601
5.52k
      ast, template_param_infos, template_param_decls);
1602
1603
5.52k
  CXXRecordDecl *template_cxx_decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1604
5.52k
  template_cxx_decl->setTagKind(static_cast<TagDecl::TagKind>(kind));
1605
  // What decl context do we use here? TU? The actual decl context?
1606
5.52k
  template_cxx_decl->setDeclContext(decl_ctx);
1607
5.52k
  template_cxx_decl->setDeclName(decl_name);
1608
5.52k
  SetOwningModule(template_cxx_decl, owning_module);
1609
1610
5.52k
  for (size_t i = 0, template_param_decl_count = template_param_decls.size();
1611
14.1k
       i < template_param_decl_count; 
++i8.60k
) {
1612
8.60k
    template_param_decls[i]->setDeclContext(template_cxx_decl);
1613
8.60k
  }
1614
1615
  // With templated classes, we say that a class is templated with
1616
  // specializations, but that the bare class has no functions.
1617
  // template_cxx_decl->startDefinition();
1618
  // template_cxx_decl->completeDefinition();
1619
1620
5.52k
  class_template_decl = ClassTemplateDecl::CreateDeserialized(ast, 0);
1621
  // What decl context do we use here? TU? The actual decl context?
1622
5.52k
  class_template_decl->setDeclContext(decl_ctx);
1623
5.52k
  class_template_decl->setDeclName(decl_name);
1624
5.52k
  class_template_decl->init(template_cxx_decl, template_param_list);
1625
5.52k
  template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1626
5.52k
  SetOwningModule(class_template_decl, owning_module);
1627
1628
5.52k
  if (access_type != eAccessNone)
1629
122
    class_template_decl->setAccess(
1630
122
        ConvertAccessTypeToAccessSpecifier(access_type));
1631
1632
5.52k
  decl_ctx->addDecl(class_template_decl);
1633
1634
5.52k
  VerifyDecl(class_template_decl);
1635
1636
5.52k
  return class_template_decl;
1637
8.52k
}
1638
1639
TemplateTemplateParmDecl *
1640
33
TypeSystemClang::CreateTemplateTemplateParmDecl(const char *template_name) {
1641
33
  ASTContext &ast = getASTContext();
1642
1643
33
  auto *decl_ctx = ast.getTranslationUnitDecl();
1644
1645
33
  IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1646
33
  llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1647
1648
33
  TypeSystemClang::TemplateParameterInfos template_param_infos;
1649
33
  TemplateParameterList *template_param_list = CreateTemplateParameterList(
1650
33
      ast, template_param_infos, template_param_decls);
1651
1652
  // LLDB needs to create those decls only to be able to display a
1653
  // type that includes a template template argument. Only the name matters for
1654
  // this purpose, so we use dummy values for the other characteristics of the
1655
  // type.
1656
33
  return TemplateTemplateParmDecl::Create(
1657
33
      ast, decl_ctx, SourceLocation(),
1658
33
      /*Depth*/ 0, /*Position*/ 0,
1659
33
      /*IsParameterPack*/ false, &identifier_info, template_param_list);
1660
33
}
1661
1662
ClassTemplateSpecializationDecl *
1663
TypeSystemClang::CreateClassTemplateSpecializationDecl(
1664
    DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1665
    ClassTemplateDecl *class_template_decl, int kind,
1666
8.49k
    const TemplateParameterInfos &template_param_infos) {
1667
8.49k
  ASTContext &ast = getASTContext();
1668
8.49k
  llvm::SmallVector<clang::TemplateArgument, 2> args(
1669
8.49k
      template_param_infos.args.size() +
1670
8.49k
      (template_param_infos.packed_args ? 
1308
:
08.18k
));
1671
8.49k
  std::copy(template_param_infos.args.begin(), template_param_infos.args.end(),
1672
8.49k
            args.begin());
1673
8.49k
  if (template_param_infos.packed_args) {
1674
308
    args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1675
308
        ast, template_param_infos.packed_args->args);
1676
308
  }
1677
8.49k
  ClassTemplateSpecializationDecl *class_template_specialization_decl =
1678
8.49k
      ClassTemplateSpecializationDecl::CreateDeserialized(ast, 0);
1679
8.49k
  class_template_specialization_decl->setTagKind(
1680
8.49k
      static_cast<TagDecl::TagKind>(kind));
1681
8.49k
  class_template_specialization_decl->setDeclContext(decl_ctx);
1682
8.49k
  class_template_specialization_decl->setInstantiationOf(class_template_decl);
1683
8.49k
  class_template_specialization_decl->setTemplateArgs(
1684
8.49k
      TemplateArgumentList::CreateCopy(ast, args));
1685
8.49k
  ast.getTypeDeclType(class_template_specialization_decl, nullptr);
1686
8.49k
  class_template_specialization_decl->setDeclName(
1687
8.49k
      class_template_decl->getDeclName());
1688
8.49k
  SetOwningModule(class_template_specialization_decl, owning_module);
1689
8.49k
  decl_ctx->addDecl(class_template_specialization_decl);
1690
1691
8.49k
  class_template_specialization_decl->setSpecializationKind(
1692
8.49k
      TSK_ExplicitSpecialization);
1693
1694
8.49k
  return class_template_specialization_decl;
1695
8.49k
}
1696
1697
CompilerType TypeSystemClang::CreateClassTemplateSpecializationType(
1698
8.49k
    ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1699
8.49k
  if (class_template_specialization_decl) {
1700
8.49k
    ASTContext &ast = getASTContext();
1701
8.49k
    return GetType(ast.getTagDeclType(class_template_specialization_decl));
1702
8.49k
  }
1703
0
  return CompilerType();
1704
8.49k
}
1705
1706
static inline bool check_op_param(bool is_method,
1707
                                  clang::OverloadedOperatorKind op_kind,
1708
                                  bool unary, bool binary,
1709
4.31k
                                  uint32_t num_params) {
1710
  // Special-case call since it can take any number of operands
1711
4.31k
  if (op_kind == OO_Call)
1712
244
    return true;
1713
1714
  // The parameter count doesn't include "this"
1715
4.06k
  if (is_method)
1716
3.89k
    ++num_params;
1717
4.06k
  if (num_params == 1)
1718
341
    return unary;
1719
3.72k
  if (num_params == 2)
1720
3.59k
    return binary;
1721
137
  else
1722
137
    return false;
1723
3.72k
}
1724
1725
bool TypeSystemClang::CheckOverloadedOperatorKindParameterCount(
1726
    bool is_method, clang::OverloadedOperatorKind op_kind,
1727
4.40k
    uint32_t num_params) {
1728
4.40k
  switch (op_kind) {
1729
4.31k
  default:
1730
4.31k
    break;
1731
  // C++ standard allows any number of arguments to new/delete
1732
4.31k
  case OO_New:
1733
48
  case OO_Array_New:
1734
72
  case OO_Delete:
1735
96
  case OO_Array_Delete:
1736
96
    return true;
1737
4.40k
  }
1738
1739
4.31k
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly)  \
1740
4.31k
  case OO_##Name:                                                              \
1741
4.31k
    return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1742
4.31k
  switch (op_kind) {
1743
0
#include "clang/Basic/OperatorKinds.def"
1744
0
  default:
1745
0
    break;
1746
4.31k
  }
1747
0
  return false;
1748
4.31k
}
1749
1750
clang::AccessSpecifier
1751
TypeSystemClang::UnifyAccessSpecifiers(clang::AccessSpecifier lhs,
1752
616
                                       clang::AccessSpecifier rhs) {
1753
  // Make the access equal to the stricter of the field and the nested field's
1754
  // access
1755
616
  if (lhs == AS_none || 
rhs == AS_none613
)
1756
6
    return AS_none;
1757
610
  if (lhs == AS_private || 
rhs == AS_private607
)
1758
5
    return AS_private;
1759
605
  if (lhs == AS_protected || 
rhs == AS_protected603
)
1760
3
    return AS_protected;
1761
602
  return AS_public;
1762
605
}
1763
1764
bool TypeSystemClang::FieldIsBitfield(FieldDecl *field,
1765
43.0k
                                      uint32_t &bitfield_bit_size) {
1766
43.0k
  ASTContext &ast = getASTContext();
1767
43.0k
  if (field == nullptr)
1768
0
    return false;
1769
1770
43.0k
  if (field->isBitField()) {
1771
341
    Expr *bit_width_expr = field->getBitWidth();
1772
341
    if (bit_width_expr) {
1773
341
      if (Optional<llvm::APSInt> bit_width_apsint =
1774
341
              bit_width_expr->getIntegerConstantExpr(ast)) {
1775
341
        bitfield_bit_size = bit_width_apsint->getLimitedValue(UINT32_MAX);
1776
341
        return true;
1777
341
      }
1778
341
    }
1779
341
  }
1780
42.7k
  return false;
1781
43.0k
}
1782
1783
68.2k
bool TypeSystemClang::RecordHasFields(const RecordDecl *record_decl) {
1784
68.2k
  if (record_decl == nullptr)
1785
0
    return false;
1786
1787
68.2k
  if (!record_decl->field_empty())
1788
48.3k
    return true;
1789
1790
  // No fields, lets check this is a CXX record and check the base classes
1791
19.8k
  const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1792
19.8k
  if (cxx_record_decl) {
1793
19.8k
    CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1794
19.8k
    for (base_class = cxx_record_decl->bases_begin(),
1795
19.8k
        base_class_end = cxx_record_decl->bases_end();
1796
24.9k
         base_class != base_class_end; 
++base_class5.04k
) {
1797
12.4k
      const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1798
12.4k
          base_class->getType()->getAs<RecordType>()->getDecl());
1799
12.4k
      if (RecordHasFields(base_class_decl))
1800
7.44k
        return true;
1801
12.4k
    }
1802
19.8k
  }
1803
12.4k
  return false;
1804
19.8k
}
1805
1806
#pragma mark Objective-C Classes
1807
1808
CompilerType TypeSystemClang::CreateObjCClass(
1809
    llvm::StringRef name, clang::DeclContext *decl_ctx,
1810
    OptionalClangModuleID owning_module, bool isForwardDecl, bool isInternal,
1811
1.35k
    ClangASTMetadata *metadata) {
1812
1.35k
  ASTContext &ast = getASTContext();
1813
1.35k
  assert(!name.empty());
1814
1.35k
  if (!decl_ctx)
1815
0
    decl_ctx = ast.getTranslationUnitDecl();
1816
1817
1.35k
  ObjCInterfaceDecl *decl = ObjCInterfaceDecl::CreateDeserialized(ast, 0);
1818
1.35k
  decl->setDeclContext(decl_ctx);
1819
1.35k
  decl->setDeclName(&ast.Idents.get(name));
1820
  /*isForwardDecl,*/
1821
1.35k
  decl->setImplicit(isInternal);
1822
1.35k
  SetOwningModule(decl, owning_module);
1823
1824
1.35k
  if (metadata)
1825
1.35k
    SetMetadata(decl, *metadata);
1826
1827
1.35k
  return GetType(ast.getObjCInterfaceType(decl));
1828
1.35k
}
1829
1830
16.9k
static inline bool BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) {
1831
16.9k
  return !TypeSystemClang::RecordHasFields(b->getType()->getAsCXXRecordDecl());
1832
16.9k
}
1833
1834
uint32_t
1835
TypeSystemClang::GetNumBaseClasses(const CXXRecordDecl *cxx_record_decl,
1836
23.9k
                                   bool omit_empty_base_classes) {
1837
23.9k
  uint32_t num_bases = 0;
1838
23.9k
  if (cxx_record_decl) {
1839
23.9k
    if (omit_empty_base_classes) {
1840
23.9k
      CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1841
23.9k
      for (base_class = cxx_record_decl->bases_begin(),
1842
23.9k
          base_class_end = cxx_record_decl->bases_end();
1843
25.6k
           base_class != base_class_end; 
++base_class1.76k
) {
1844
        // Skip empty base classes
1845
1.76k
        if (BaseSpecifierIsEmpty(base_class))
1846
1.24k
          continue;
1847
514
        ++num_bases;
1848
514
      }
1849
23.9k
    } else
1850
2
      num_bases = cxx_record_decl->getNumBases();
1851
23.9k
  }
1852
23.9k
  return num_bases;
1853
23.9k
}
1854
1855
#pragma mark Namespace Declarations
1856
1857
NamespaceDecl *TypeSystemClang::GetUniqueNamespaceDeclaration(
1858
    const char *name, clang::DeclContext *decl_ctx,
1859
9.82k
    OptionalClangModuleID owning_module, bool is_inline) {
1860
9.82k
  NamespaceDecl *namespace_decl = nullptr;
1861
9.82k
  ASTContext &ast = getASTContext();
1862
9.82k
  TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1863
9.82k
  if (!decl_ctx)
1864
7.23k
    decl_ctx = translation_unit_decl;
1865
1866
9.82k
  if (name) {
1867
9.79k
    IdentifierInfo &identifier_info = ast.Idents.get(name);
1868
9.79k
    DeclarationName decl_name(&identifier_info);
1869
9.79k
    clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1870
9.79k
    for (NamedDecl *decl : result) {
1871
474
      namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1872
474
      if (namespace_decl)
1873
474
        return namespace_decl;
1874
474
    }
1875
1876
9.32k
    namespace_decl =
1877
9.32k
        NamespaceDecl::Create(ast, decl_ctx, is_inline, SourceLocation(),
1878
9.32k
                              SourceLocation(), &identifier_info, nullptr);
1879
1880
9.32k
    decl_ctx->addDecl(namespace_decl);
1881
9.32k
  } else {
1882
22
    if (decl_ctx == translation_unit_decl) {
1883
16
      namespace_decl = translation_unit_decl->getAnonymousNamespace();
1884
16
      if (namespace_decl)
1885
3
        return namespace_decl;
1886
1887
13
      namespace_decl =
1888
13
          NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
1889
13
                                SourceLocation(), nullptr, nullptr);
1890
13
      translation_unit_decl->setAnonymousNamespace(namespace_decl);
1891
13
      translation_unit_decl->addDecl(namespace_decl);
1892
13
      assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1893
13
    } else {
1894
6
      NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1895
6
      if (parent_namespace_decl) {
1896
6
        namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1897
6
        if (namespace_decl)
1898
0
          return namespace_decl;
1899
6
        namespace_decl =
1900
6
            NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
1901
6
                                  SourceLocation(), nullptr, nullptr);
1902
6
        parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1903
6
        parent_namespace_decl->addDecl(namespace_decl);
1904
6
        assert(namespace_decl ==
1905
6
               parent_namespace_decl->getAnonymousNamespace());
1906
6
      } else {
1907
0
        assert(false && "GetUniqueNamespaceDeclaration called with no name and "
1908
0
                        "no namespace as decl_ctx");
1909
0
      }
1910
6
    }
1911
22
  }
1912
  // Note: namespaces can span multiple modules, so perhaps this isn't a good
1913
  // idea.
1914
9.34k
  SetOwningModule(namespace_decl, owning_module);
1915
1916
9.34k
  VerifyDecl(namespace_decl);
1917
9.34k
  return namespace_decl;
1918
9.82k
}
1919
1920
clang::BlockDecl *
1921
TypeSystemClang::CreateBlockDeclaration(clang::DeclContext *ctx,
1922
103
                                        OptionalClangModuleID owning_module) {
1923
103
  if (ctx) {
1924
103
    clang::BlockDecl *decl =
1925
103
        clang::BlockDecl::CreateDeserialized(getASTContext(), 0);
1926
103
    decl->setDeclContext(ctx);
1927
103
    ctx->addDecl(decl);
1928
103
    SetOwningModule(decl, owning_module);
1929
103
    return decl;
1930
103
  }
1931
0
  return nullptr;
1932
103
}
1933
1934
clang::DeclContext *FindLCABetweenDecls(clang::DeclContext *left,
1935
                                        clang::DeclContext *right,
1936
48
                                        clang::DeclContext *root) {
1937
48
  if (root == nullptr)
1938
0
    return nullptr;
1939
1940
48
  std::set<clang::DeclContext *> path_left;
1941
144
  for (clang::DeclContext *d = left; d != nullptr; 
d = d->getParent()96
)
1942
96
    path_left.insert(d);
1943
1944
102
  for (clang::DeclContext *d = right; d != nullptr; 
d = d->getParent()54
)
1945
102
    if (path_left.find(d) != path_left.end())
1946
48
      return d;
1947
1948
0
  return nullptr;
1949
48
}
1950
1951
clang::UsingDirectiveDecl *TypeSystemClang::CreateUsingDirectiveDeclaration(
1952
    clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1953
48
    clang::NamespaceDecl *ns_decl) {
1954
48
  if (decl_ctx && ns_decl) {
1955
48
    auto *translation_unit = getASTContext().getTranslationUnitDecl();
1956
48
    clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1957
48
          getASTContext(), decl_ctx, clang::SourceLocation(),
1958
48
          clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1959
48
          clang::SourceLocation(), ns_decl,
1960
48
          FindLCABetweenDecls(decl_ctx, ns_decl,
1961
48
                              translation_unit));
1962
48
      decl_ctx->addDecl(using_decl);
1963
48
      SetOwningModule(using_decl, owning_module);
1964
48
      return using_decl;
1965
48
  }
1966
0
  return nullptr;
1967
48
}
1968
1969
clang::UsingDecl *
1970
TypeSystemClang::CreateUsingDeclaration(clang::DeclContext *current_decl_ctx,
1971
                                        OptionalClangModuleID owning_module,
1972
15
                                        clang::NamedDecl *target) {
1973
15
  if (current_decl_ctx && target) {
1974
15
    clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1975
15
        getASTContext(), current_decl_ctx, clang::SourceLocation(),
1976
15
        clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(), false);
1977
15
    SetOwningModule(using_decl, owning_module);
1978
15
    clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1979
15
        getASTContext(), current_decl_ctx, clang::SourceLocation(),
1980
15
        target->getDeclName(), using_decl, target);
1981
15
    SetOwningModule(shadow_decl, owning_module);
1982
15
    using_decl->addShadowDecl(shadow_decl);
1983
15
    current_decl_ctx->addDecl(using_decl);
1984
15
    return using_decl;
1985
15
  }
1986
0
  return nullptr;
1987
15
}
1988
1989
clang::VarDecl *TypeSystemClang::CreateVariableDeclaration(
1990
    clang::DeclContext *decl_context, OptionalClangModuleID owning_module,
1991
7.82k
    const char *name, clang::QualType type) {
1992
7.82k
  if (decl_context) {
1993
7.82k
    clang::VarDecl *var_decl =
1994
7.82k
        clang::VarDecl::CreateDeserialized(getASTContext(), 0);
1995
7.82k
    var_decl->setDeclContext(decl_context);
1996
7.82k
    if (name && 
name[0]7.79k
)
1997
7.79k
      var_decl->setDeclName(&getASTContext().Idents.getOwn(name));
1998
7.82k
    var_decl->setType(type);
1999
7.82k
    SetOwningModule(var_decl, owning_module);
2000
7.82k
    var_decl->setAccess(clang::AS_public);
2001
7.82k
    decl_context->addDecl(var_decl);
2002
7.82k
    return var_decl;
2003
7.82k
  }
2004
0
  return nullptr;
2005
7.82k
}
2006
2007
lldb::opaque_compiler_type_t
2008
TypeSystemClang::GetOpaqueCompilerType(clang::ASTContext *ast,
2009
35.5k
                                       lldb::BasicType basic_type) {
2010
35.5k
  switch (basic_type) {
2011
33.7k
  case eBasicTypeVoid:
2012
33.7k
    return ast->VoidTy.getAsOpaquePtr();
2013
104
  case eBasicTypeChar:
2014
104
    return ast->CharTy.getAsOpaquePtr();
2015
3
  case eBasicTypeSignedChar:
2016
3
    return ast->SignedCharTy.getAsOpaquePtr();
2017
3
  case eBasicTypeUnsignedChar:
2018
3
    return ast->UnsignedCharTy.getAsOpaquePtr();
2019
119
  case eBasicTypeWChar:
2020
119
    return ast->getWCharType().getAsOpaquePtr();
2021
2
  case eBasicTypeSignedWChar:
2022
2
    return ast->getSignedWCharType().getAsOpaquePtr();
2023
2
  case eBasicTypeUnsignedWChar:
2024
2
    return ast->getUnsignedWCharType().getAsOpaquePtr();
2025
1
  case eBasicTypeChar16:
2026
1
    return ast->Char16Ty.getAsOpaquePtr();
2027
1
  case eBasicTypeChar32:
2028
1
    return ast->Char32Ty.getAsOpaquePtr();
2029
5
  case eBasicTypeShort:
2030
5
    return ast->ShortTy.getAsOpaquePtr();
2031
5
  case eBasicTypeUnsignedShort:
2032
5
    return ast->UnsignedShortTy.getAsOpaquePtr();
2033
80
  case eBasicTypeInt:
2034
80
    return ast->IntTy.getAsOpaquePtr();
2035
79
  case eBasicTypeUnsignedInt:
2036
79
    return ast->UnsignedIntTy.getAsOpaquePtr();
2037
9
  case eBasicTypeLong:
2038
9
    return ast->LongTy.getAsOpaquePtr();
2039
8
  case eBasicTypeUnsignedLong:
2040
8
    return ast->UnsignedLongTy.getAsOpaquePtr();
2041
7
  case eBasicTypeLongLong:
2042
7
    return ast->LongLongTy.getAsOpaquePtr();
2043
7
  case eBasicTypeUnsignedLongLong:
2044
7
    return ast->UnsignedLongLongTy.getAsOpaquePtr();
2045
3
  case eBasicTypeInt128:
2046
3
    return ast->Int128Ty.getAsOpaquePtr();
2047
3
  case eBasicTypeUnsignedInt128:
2048
3
    return ast->UnsignedInt128Ty.getAsOpaquePtr();
2049
191
  case eBasicTypeBool:
2050
191
    return ast->BoolTy.getAsOpaquePtr();
2051
1
  case eBasicTypeHalf:
2052
1
    return ast->HalfTy.getAsOpaquePtr();
2053
3
  case eBasicTypeFloat:
2054
3
    return ast->FloatTy.getAsOpaquePtr();
2055
5
  case eBasicTypeDouble:
2056
5
    return ast->DoubleTy.getAsOpaquePtr();
2057
3
  case eBasicTypeLongDouble:
2058
3
    return ast->LongDoubleTy.getAsOpaquePtr();
2059
1
  case eBasicTypeFloatComplex:
2060
1
    return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2061
1
  case eBasicTypeDoubleComplex:
2062
1
    return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2063
1
  case eBasicTypeLongDoubleComplex:
2064
1
    return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2065
655
  case eBasicTypeObjCID:
2066
655
    return ast->getObjCIdType().getAsOpaquePtr();
2067
279
  case eBasicTypeObjCClass:
2068
279
    return ast->getObjCClassType().getAsOpaquePtr();
2069
70
  case eBasicTypeObjCSel:
2070
70
    return ast->getObjCSelType().getAsOpaquePtr();
2071
148
  case eBasicTypeNullPtr:
2072
148
    return ast->NullPtrTy.getAsOpaquePtr();
2073
4
  default:
2074
4
    return nullptr;
2075
35.5k
  }
2076
35.5k
}
2077
2078
#pragma mark Function Types
2079
2080
clang::DeclarationName
2081
TypeSystemClang::GetDeclarationName(llvm::StringRef name,
2082
7.01k
                                    const CompilerType &function_clang_type) {
2083
7.01k
  clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2084
7.01k
  if (!IsOperator(name, op_kind) || 
op_kind == clang::NUM_OVERLOADED_OPERATORS43
)
2085
6.97k
    return DeclarationName(&getASTContext().Idents.get(
2086
6.97k
        name)); // Not operator, but a regular function.
2087
2088
  // Check the number of operator parameters. Sometimes we have seen bad DWARF
2089
  // that doesn't correctly describe operators and if we try to create a method
2090
  // and add it to the class, clang will assert and crash, so we need to make
2091
  // sure things are acceptable.
2092
43
  clang::QualType method_qual_type(ClangUtil::GetQualType(function_clang_type));
2093
43
  const clang::FunctionProtoType *function_type =
2094
43
      llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2095
43
  if (function_type == nullptr)
2096
0
    return clang::DeclarationName();
2097
2098
43
  const bool is_method = false;
2099
43
  const unsigned int num_params = function_type->getNumParams();
2100
43
  if (!TypeSystemClang::CheckOverloadedOperatorKindParameterCount(
2101
43
          is_method, op_kind, num_params))
2102
12
    return clang::DeclarationName();
2103
2104
31
  return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2105
43
}
2106
2107
442k
PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() {
2108
442k
  clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
2109
442k
  printing_policy.SuppressTagKeyword = true;
2110
  // Inline namespaces are important for some type formatters (e.g., libc++
2111
  // and libstdc++ are differentiated by their inline namespaces).
2112
442k
  printing_policy.SuppressInlineNamespace = false;
2113
442k
  printing_policy.SuppressUnwrittenScope = false;
2114
  // Default arguments are also always important for type formatters. Otherwise
2115
  // we would need to always specify two type names for the setups where we do
2116
  // know the default arguments and where we don't know default arguments.
2117
  //
2118
  // For example, without this we would need to have formatters for both:
2119
  //   std::basic_string<char>
2120
  // and
2121
  //   std::basic_string<char, std::char_traits<char>, std::allocator<char> >
2122
  // to support setups where LLDB was able to reconstruct default arguments
2123
  // (and we then would have suppressed them from the type name) and also setups
2124
  // where LLDB wasn't able to reconstruct the default arguments.
2125
442k
  printing_policy.SuppressDefaultTemplateArgs = false;
2126
442k
  return printing_policy;
2127
442k
}
2128
2129
127k
std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl) {
2130
127k
  clang::PrintingPolicy printing_policy = GetTypePrintingPolicy();
2131
127k
  std::string result;
2132
127k
  llvm::raw_string_ostream os(result);
2133
127k
  named_decl->printQualifiedName(os, printing_policy);
2134
127k
  return result;
2135
127k
}
2136
2137
FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
2138
    clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
2139
    llvm::StringRef name, const CompilerType &function_clang_type,
2140
7.01k
    clang::StorageClass storage, bool is_inline) {
2141
7.01k
  FunctionDecl *func_decl = nullptr;
2142
7.01k
  ASTContext &ast = getASTContext();
2143
7.01k
  if (!decl_ctx)
2144
0
    decl_ctx = ast.getTranslationUnitDecl();
2145
2146
7.01k
  const bool hasWrittenPrototype = true;
2147
7.01k
  const bool isConstexprSpecified = false;
2148
2149
7.01k
  clang::DeclarationName declarationName =
2150
7.01k
      GetDeclarationName(name, function_clang_type);
2151
7.01k
  func_decl = FunctionDecl::CreateDeserialized(ast, 0);
2152
7.01k
  func_decl->setDeclContext(decl_ctx);
2153
7.01k
  func_decl->setDeclName(declarationName);
2154
7.01k
  func_decl->setType(ClangUtil::GetQualType(function_clang_type));
2155
7.01k
  func_decl->setStorageClass(storage);
2156
7.01k
  func_decl->setInlineSpecified(is_inline);
2157
7.01k
  func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2158
7.01k
  func_decl->setConstexprKind(isConstexprSpecified
2159
7.01k
                                  ? 
ConstexprSpecKind::Constexpr0
2160
7.01k
                                  : ConstexprSpecKind::Unspecified);
2161
7.01k
  SetOwningModule(func_decl, owning_module);
2162
7.01k
  decl_ctx->addDecl(func_decl);
2163
2164
7.01k
  VerifyDecl(func_decl);
2165
2166
7.01k
  return func_decl;
2167
7.01k
}
2168
2169
CompilerType
2170
TypeSystemClang::CreateFunctionType(const CompilerType &result_type,
2171
                                    const CompilerType *args, unsigned num_args,
2172
                                    bool is_variadic, unsigned type_quals,
2173
66.2k
                                    clang::CallingConv cc) {
2174
66.2k
  if (!result_type || !ClangUtil::IsClangType(result_type))
2175
0
    return CompilerType(); // invalid return type
2176
2177
66.2k
  std::vector<QualType> qual_type_args;
2178
66.2k
  if (num_args > 0 && 
args == nullptr40.8k
)
2179
0
    return CompilerType(); // invalid argument array passed in
2180
2181
  // Verify that all arguments are valid and the right type
2182
132k
  
for (unsigned i = 0; 66.2k
i < num_args;
++i66.3k
) {
2183
66.3k
    if (args[i]) {
2184
      // Make sure we have a clang type in args[i] and not a type from another
2185
      // language whose name might match
2186
66.3k
      const bool is_clang_type = ClangUtil::IsClangType(args[i]);
2187
66.3k
      lldbassert(is_clang_type);
2188
66.3k
      if (is_clang_type)
2189
66.3k
        qual_type_args.push_back(ClangUtil::GetQualType(args[i]));
2190
0
      else
2191
0
        return CompilerType(); //  invalid argument type (must be a clang type)
2192
66.3k
    } else
2193
0
      return CompilerType(); // invalid argument type (empty)
2194
66.3k
  }
2195
2196
  // TODO: Detect calling convention in DWARF?
2197
66.2k
  FunctionProtoType::ExtProtoInfo proto_info;
2198
66.2k
  proto_info.ExtInfo = cc;
2199
66.2k
  proto_info.Variadic = is_variadic;
2200
66.2k
  proto_info.ExceptionSpec = EST_None;
2201
66.2k
  proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2202
66.2k
  proto_info.RefQualifier = RQ_None;
2203
2204
66.2k
  return GetType(getASTContext().getFunctionType(
2205
66.2k
      ClangUtil::GetQualType(result_type), qual_type_args, proto_info));
2206
66.2k
}
2207
2208
ParmVarDecl *TypeSystemClang::CreateParameterDeclaration(
2209
    clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
2210
    const char *name, const CompilerType &param_type, int storage,
2211
66.1k
    bool add_decl) {
2212
66.1k
  ASTContext &ast = getASTContext();
2213
66.1k
  auto *decl = ParmVarDecl::CreateDeserialized(ast, 0);
2214
66.1k
  decl->setDeclContext(decl_ctx);
2215
66.1k
  if (name && 
name[0]2.58k
)
2216
2.58k
    decl->setDeclName(&ast.Idents.get(name));
2217
66.1k
  decl->setType(ClangUtil::GetQualType(param_type));
2218
66.1k
  decl->setStorageClass(static_cast<clang::StorageClass>(storage));
2219
66.1k
  SetOwningModule(decl, owning_module);
2220
66.1k
  if (add_decl)
2221
0
    decl_ctx->addDecl(decl);
2222
2223
66.1k
  return decl;
2224
66.1k
}
2225
2226
void TypeSystemClang::SetFunctionParameters(
2227
5.73k
    FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2228
5.73k
  if (function_decl)
2229
5.73k
    function_decl->setParams(params);
2230
5.73k
}
2231
2232
CompilerType
2233
17
TypeSystemClang::CreateBlockPointerType(const CompilerType &function_type) {
2234
17
  QualType block_type = m_ast_up->getBlockPointerType(
2235
17
      clang::QualType::getFromOpaquePtr(function_type.GetOpaqueQualType()));
2236
2237
17
  return GetType(block_type);
2238
17
}
2239
2240
#pragma mark Array Types
2241
2242
CompilerType TypeSystemClang::CreateArrayType(const CompilerType &element_type,
2243
                                              size_t element_count,
2244
960
                                              bool is_vector) {
2245
960
  if (element_type.IsValid()) {
2246
960
    ASTContext &ast = getASTContext();
2247
2248
960
    if (is_vector) {
2249
43
      return GetType(ast.getExtVectorType(ClangUtil::GetQualType(element_type),
2250
43
                                          element_count));
2251
917
    } else {
2252
2253
917
      llvm::APInt ap_element_count(64, element_count);
2254
917
      if (element_count == 0) {
2255
33
        return GetType(ast.getIncompleteArrayType(
2256
33
            ClangUtil::GetQualType(element_type), clang::ArrayType::Normal, 0));
2257
884
      } else {
2258
884
        return GetType(ast.getConstantArrayType(
2259
884
            ClangUtil::GetQualType(element_type), ap_element_count, nullptr,
2260
884
            clang::ArrayType::Normal, 0));
2261
884
      }
2262
917
    }
2263
960
  }
2264
0
  return CompilerType();
2265
960
}
2266
2267
CompilerType TypeSystemClang::CreateStructForIdentifier(
2268
    ConstString type_name,
2269
    const std::initializer_list<std::pair<const char *, CompilerType>>
2270
        &type_fields,
2271
159
    bool packed) {
2272
159
  CompilerType type;
2273
159
  if (!type_name.IsEmpty() &&
2274
159
      (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2275
0
          .IsValid()) {
2276
0
    lldbassert(0 && "Trying to create a type for an existing name");
2277
0
    return type;
2278
0
  }
2279
2280
159
  type = CreateRecordType(nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
2281
159
                          type_name.GetCString(), clang::TTK_Struct,
2282
159
                          lldb::eLanguageTypeC);
2283
159
  StartTagDeclarationDefinition(type);
2284
159
  for (const auto &field : type_fields)
2285
783
    AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic,
2286
783
                         0);
2287
159
  if (packed)
2288
0
    SetIsPacked(type);
2289
159
  CompleteTagDeclarationDefinition(type);
2290
159
  return type;
2291
159
}
2292
2293
CompilerType TypeSystemClang::GetOrCreateStructForIdentifier(
2294
    ConstString type_name,
2295
    const std::initializer_list<std::pair<const char *, CompilerType>>
2296
        &type_fields,
2297
0
    bool packed) {
2298
0
  CompilerType type;
2299
0
  if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2300
0
    return type;
2301
2302
0
  return CreateStructForIdentifier(type_name, type_fields, packed);
2303
0
}
2304
2305
#pragma mark Enumeration Types
2306
2307
CompilerType TypeSystemClang::CreateEnumerationType(
2308
    llvm::StringRef name, clang::DeclContext *decl_ctx,
2309
    OptionalClangModuleID owning_module, const Declaration &decl,
2310
112
    const CompilerType &integer_clang_type, bool is_scoped) {
2311
  // TODO: Do something intelligent with the Declaration object passed in
2312
  // like maybe filling in the SourceLocation with it...
2313
112
  ASTContext &ast = getASTContext();
2314
2315
  // TODO: ask about these...
2316
  //    const bool IsFixed = false;
2317
112
  EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, 0);
2318
112
  enum_decl->setDeclContext(decl_ctx);
2319
112
  if (!name.empty())
2320
107
    enum_decl->setDeclName(&ast.Idents.get(name));
2321
112
  enum_decl->setScoped(is_scoped);
2322
112
  enum_decl->setScopedUsingClassTag(is_scoped);
2323
112
  enum_decl->setFixed(false);
2324
112
  SetOwningModule(enum_decl, owning_module);
2325
112
  if (decl_ctx)
2326
112
    decl_ctx->addDecl(enum_decl);
2327
2328
  // TODO: check if we should be setting the promotion type too?
2329
112
  enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type));
2330
2331
112
  enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
2332
2333
112
  return GetType(ast.getTagDeclType(enum_decl));
2334
112
}
2335
2336
CompilerType TypeSystemClang::GetIntTypeFromBitSize(size_t bit_size,
2337
30
                                                    bool is_signed) {
2338
30
  clang::ASTContext &ast = getASTContext();
2339
2340
30
  if (is_signed) {
2341
0
    if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2342
0
      return GetType(ast.SignedCharTy);
2343
2344
0
    if (bit_size == ast.getTypeSize(ast.ShortTy))
2345
0
      return GetType(ast.ShortTy);
2346
2347
0
    if (bit_size == ast.getTypeSize(ast.IntTy))
2348
0
      return GetType(ast.IntTy);
2349
2350
0
    if (bit_size == ast.getTypeSize(ast.LongTy))
2351
0
      return GetType(ast.LongTy);
2352
2353
0
    if (bit_size == ast.getTypeSize(ast.LongLongTy))
2354
0
      return GetType(ast.LongLongTy);
2355
2356
0
    if (bit_size == ast.getTypeSize(ast.Int128Ty))
2357
0
      return GetType(ast.Int128Ty);
2358
30
  } else {
2359
30
    if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2360
0
      return GetType(ast.UnsignedCharTy);
2361
2362
30
    if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2363
0
      return GetType(ast.UnsignedShortTy);
2364
2365
30
    if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2366
0
      return GetType(ast.UnsignedIntTy);
2367
2368
30
    if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2369
30
      return GetType(ast.UnsignedLongTy);
2370
2371
0
    if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2372
0
      return GetType(ast.UnsignedLongLongTy);
2373
2374
0
    if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2375
0
      return GetType(ast.UnsignedInt128Ty);
2376
0
  }
2377
0
  return CompilerType();
2378
30
}
2379
2380
30
CompilerType TypeSystemClang::GetPointerSizedIntType(bool is_signed) {
2381
30
  return GetIntTypeFromBitSize(
2382
30
      getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed);
2383
30
}
2384
2385
0
void TypeSystemClang::DumpDeclContextHiearchy(clang::DeclContext *decl_ctx) {
2386
0
  if (decl_ctx) {
2387
0
    DumpDeclContextHiearchy(decl_ctx->getParent());
2388
2389
0
    clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2390
0
    if (named_decl) {
2391
0
      printf("%20s: %s\n", decl_ctx->getDeclKindName(),
2392
0
             named_decl->getDeclName().getAsString().c_str());
2393
0
    } else {
2394
0
      printf("%20s\n", decl_ctx->getDeclKindName());
2395
0
    }
2396
0
  }
2397
0
}
2398
2399
0
void TypeSystemClang::DumpDeclHiearchy(clang::Decl *decl) {
2400
0
  if (decl == nullptr)
2401
0
    return;
2402
0
  DumpDeclContextHiearchy(decl->getDeclContext());
2403
2404
0
  clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2405
0
  if (record_decl) {
2406
0
    printf("%20s: %s%s\n", decl->getDeclKindName(),
2407
0
           record_decl->getDeclName().getAsString().c_str(),
2408
0
           record_decl->isInjectedClassName() ? " (injected class name)" : "");
2409
2410
0
  } else {
2411
0
    clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2412
0
    if (named_decl) {
2413
0
      printf("%20s: %s\n", decl->getDeclKindName(),
2414
0
             named_decl->getDeclName().getAsString().c_str());
2415
0
    } else {
2416
0
      printf("%20s\n", decl->getDeclKindName());
2417
0
    }
2418
0
  }
2419
0
}
2420
2421
bool TypeSystemClang::DeclsAreEquivalent(clang::Decl *lhs_decl,
2422
9
                                         clang::Decl *rhs_decl) {
2423
9
  if (lhs_decl && rhs_decl) {
2424
    // Make sure the decl kinds match first
2425
9
    const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind();
2426
9
    const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind();
2427
2428
9
    if (lhs_decl_kind == rhs_decl_kind) {
2429
      // Now check that the decl contexts kinds are all equivalent before we
2430
      // have to check any names of the decl contexts...
2431
9
      clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext();
2432
9
      clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext();
2433
9
      if (lhs_decl_ctx && rhs_decl_ctx) {
2434
9
        while (true) {
2435
9
          if (lhs_decl_ctx && rhs_decl_ctx) {
2436
9
            const clang::Decl::Kind lhs_decl_ctx_kind =
2437
9
                lhs_decl_ctx->getDeclKind();
2438
9
            const clang::Decl::Kind rhs_decl_ctx_kind =
2439
9
                rhs_decl_ctx->getDeclKind();
2440
9
            if (lhs_decl_ctx_kind == rhs_decl_ctx_kind) {
2441
9
              lhs_decl_ctx = lhs_decl_ctx->getParent();
2442
9
              rhs_decl_ctx = rhs_decl_ctx->getParent();
2443
2444
9
              if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr)
2445
9
                break;
2446
9
            } else
2447
0
              return false;
2448
9
          } else
2449
0
            return false;
2450
9
        }
2451
2452
        // Now make sure the name of the decls match
2453
9
        clang::NamedDecl *lhs_named_decl =
2454
9
            llvm::dyn_cast<clang::NamedDecl>(lhs_decl);
2455
9
        clang::NamedDecl *rhs_named_decl =
2456
9
            llvm::dyn_cast<clang::NamedDecl>(rhs_decl);
2457
9
        if (lhs_named_decl && rhs_named_decl) {
2458
9
          clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
2459
9
          clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
2460
9
          if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) {
2461
9
            if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2462
0
              return false;
2463
9
          } else
2464
0
            return false;
2465
9
        } else
2466
0
          return false;
2467
2468
        // We know that the decl context kinds all match, so now we need to
2469
        // make sure the names match as well
2470
9
        lhs_decl_ctx = lhs_decl->getDeclContext();
2471
9
        rhs_decl_ctx = rhs_decl->getDeclContext();
2472
9
        while (true) {
2473
9
          switch (lhs_decl_ctx->getDeclKind()) {
2474
9
          case clang::Decl::TranslationUnit:
2475
            // We don't care about the translation unit names
2476
9
            return true;
2477
0
          default: {
2478
0
            clang::NamedDecl *lhs_named_decl =
2479
0
                llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx);
2480
0
            clang::NamedDecl *rhs_named_decl =
2481
0
                llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx);
2482
0
            if (lhs_named_decl && rhs_named_decl) {
2483
0
              clang::DeclarationName lhs_decl_name =
2484
0
                  lhs_named_decl->getDeclName();
2485
0
              clang::DeclarationName rhs_decl_name =
2486
0
                  rhs_named_decl->getDeclName();
2487
0
              if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) {
2488
0
                if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2489
0
                  return false;
2490
0
              } else
2491
0
                return false;
2492
0
            } else
2493
0
              return false;
2494
0
          } break;
2495
9
          }
2496
0
          lhs_decl_ctx = lhs_decl_ctx->getParent();
2497
0
          rhs_decl_ctx = rhs_decl_ctx->getParent();
2498
0
        }
2499
9
      }
2500
9
    }
2501
9
  }
2502
0
  return false;
2503
9
}
2504
bool TypeSystemClang::GetCompleteDecl(clang::ASTContext *ast,
2505
100k
                                      clang::Decl *decl) {
2506
100k
  if (!decl)
2507
0
    return false;
2508
2509
100k
  ExternalASTSource *ast_source = ast->getExternalSource();
2510
2511
100k
  if (!ast_source)
2512
0
    return false;
2513
2514
100k
  if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2515
97.7k
    if (tag_decl->isCompleteDefinition())
2516
83.4k
      return true;
2517
2518
14.2k
    if (!tag_decl->hasExternalLexicalStorage())
2519
14.1k
      return false;
2520
2521
189
    ast_source->CompleteType(tag_decl);
2522
2523
189
    return !tag_decl->getTypeForDecl()->isIncompleteType();
2524
14.2k
  } else 
if (clang::ObjCInterfaceDecl *3.25k
objc_interface_decl3.25k
=
2525
3.25k
                 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2526
3.25k
    if (objc_interface_decl->getDefinition())
2527
3.07k
      return true;
2528
2529
179
    if (!objc_interface_decl->hasExternalLexicalStorage())
2530
5
      return false;
2531
2532
174
    ast_source->CompleteType(objc_interface_decl);
2533
2534
174
    return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2535
179
  } else {
2536
0
    return false;
2537
0
  }
2538
100k
}
2539
2540
void TypeSystemClang::SetMetadataAsUserID(const clang::Decl *decl,
2541
75.1k
                                          user_id_t user_id) {
2542
75.1k
  ClangASTMetadata meta_data;
2543
75.1k
  meta_data.SetUserID(user_id);
2544
75.1k
  SetMetadata(decl, meta_data);
2545
75.1k
}
2546
2547
void TypeSystemClang::SetMetadataAsUserID(const clang::Type *type,
2548
921
                                          user_id_t user_id) {
2549
921
  ClangASTMetadata meta_data;
2550
921
  meta_data.SetUserID(user_id);
2551
921
  SetMetadata(type, meta_data);
2552
921
}
2553
2554
void TypeSystemClang::SetMetadata(const clang::Decl *object,
2555
163k
                                  ClangASTMetadata &metadata) {
2556
163k
  m_decl_metadata[object] = metadata;
2557
163k
}
2558
2559
void TypeSystemClang::SetMetadata(const clang::Type *object,
2560
921
                                  ClangASTMetadata &metadata) {
2561
921
  m_type_metadata[object] = metadata;
2562
921
}
2563
2564
5.57M
ClangASTMetadata *TypeSystemClang::GetMetadata(const clang::Decl *object) {
2565
5.57M
  auto It = m_decl_metadata.find(object);
2566
5.57M
  if (It != m_decl_metadata.end())
2567
893k
    return &It->second;
2568
4.67M
  return nullptr;
2569
5.57M
}
2570
2571
42
ClangASTMetadata *TypeSystemClang::GetMetadata(const clang::Type *object) {
2572
42
  auto It = m_type_metadata.find(object);
2573
42
  if (It != m_type_metadata.end())
2574
39
    return &It->second;
2575
3
  return nullptr;
2576
42
}
2577
2578
void TypeSystemClang::SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object,
2579
83.1k
                                             clang::AccessSpecifier access) {
2580
83.1k
  if (access == clang::AccessSpecifier::AS_none)
2581
10.2k
    m_cxx_record_decl_access.erase(object);
2582
72.9k
  else
2583
72.9k
    m_cxx_record_decl_access[object] = access;
2584
83.1k
}
2585
2586
clang::AccessSpecifier
2587
72.9k
TypeSystemClang::GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object) {
2588
72.9k
  auto It = m_cxx_record_decl_access.find(object);
2589
72.9k
  if (It != m_cxx_record_decl_access.end())
2590
65.0k
    return It->second;
2591
7.95k
  return clang::AccessSpecifier::AS_none;
2592
72.9k
}
2593
2594
clang::DeclContext *
2595
13.9k
TypeSystemClang::GetDeclContextForType(const CompilerType &type) {
2596
13.9k
  return GetDeclContextForType(ClangUtil::GetQualType(type));
2597
13.9k
}
2598
2599
/// Aggressively desugar the provided type, skipping past various kinds of
2600
/// syntactic sugar and other constructs one typically wants to ignore.
2601
/// The \p mask argument allows one to skip certain kinds of simplifications,
2602
/// when one wishes to handle a certain kind of type directly.
2603
static QualType
2604
3.27M
RemoveWrappingTypes(QualType type, ArrayRef<clang::Type::TypeClass> mask = {}) {
2605
3.62M
  while (true) {
2606
3.62M
    if (find(mask, type->getTypeClass()) != mask.end())
2607
218k
      return type;
2608
3.40M
    switch (type->getTypeClass()) {
2609
    // This is not fully correct as _Atomic is more than sugar, but it is
2610
    // sufficient for the purposes we care about.
2611
64
    case clang::Type::Atomic:
2612
64
      type = cast<clang::AtomicType>(type)->getValueType();
2613
64
      break;
2614
181
    case clang::Type::Auto:
2615
196
    case clang::Type::Decltype:
2616
12.2k
    case clang::Type::Elaborated:
2617
12.4k
    case clang::Type::Paren:
2618
21.4k
    case clang::Type::SubstTemplateTypeParm:
2619
26.5k
    case clang::Type::TemplateSpecialization:
2620
349k
    case clang::Type::Typedef:
2621
349k
    case clang::Type::TypeOf:
2622
349k
    case clang::Type::TypeOfExpr:
2623
350k
    case clang::Type::Using:
2624
350k
      type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2625
350k
      break;
2626
3.05M
    default:
2627
3.05M
      return type;
2628
3.40M
    }
2629
3.40M
  }
2630
3.27M
}
2631
2632
clang::DeclContext *
2633
14.7k
TypeSystemClang::GetDeclContextForType(clang::QualType type) {
2634
14.7k
  if (type.isNull())
2635
0
    return nullptr;
2636
2637
14.7k
  clang::QualType qual_type = RemoveWrappingTypes(type.getCanonicalType());
2638
14.7k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2639
14.7k
  switch (type_class) {
2640
2.11k
  case clang::Type::ObjCInterface:
2641
2.11k
    return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2642
2.11k
        ->getInterface();
2643
0
  case clang::Type::ObjCObjectPointer:
2644
0
    return GetDeclContextForType(
2645
0
        llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2646
0
            ->getPointeeType());
2647
12.4k
  case clang::Type::Record:
2648
12.4k
    return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2649
99
  case clang::Type::Enum:
2650
99
    return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2651
0
  default:
2652
0
    break;
2653
14.7k
  }
2654
  // No DeclContext in this type...
2655
0
  return nullptr;
2656
14.7k
}
2657
2658
static bool GetCompleteQualType(clang::ASTContext *ast,
2659
                                clang::QualType qual_type,
2660
833k
                                bool allow_completion = true) {
2661
833k
  qual_type = RemoveWrappingTypes(qual_type);
2662
833k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2663
833k
  switch (type_class) {
2664
2.77k
  case clang::Type::ConstantArray:
2665
2.79k
  case clang::Type::IncompleteArray:
2666
2.79k
  case clang::Type::VariableArray: {
2667
2.79k
    const clang::ArrayType *array_type =
2668
2.79k
        llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2669
2670
2.79k
    if (array_type)
2671
2.79k
      return GetCompleteQualType(ast, array_type->getElementType(),
2672
2.79k
                                 allow_completion);
2673
2.79k
  } 
break0
;
2674
256k
  case clang::Type::Record: {
2675
256k
    clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2676
256k
    if (cxx_record_decl) {
2677
256k
      if (cxx_record_decl->hasExternalLexicalStorage()) {
2678
16.1k
        const bool is_complete = cxx_record_decl->isCompleteDefinition();
2679
16.1k
        const bool fields_loaded =
2680
16.1k
            cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2681
16.1k
        if (is_complete && 
fields_loaded14.8k
)
2682
14.2k
          return true;
2683
2684
1.85k
        if (!allow_completion)
2685
0
          return false;
2686
2687
        // Call the field_begin() accessor to for it to use the external source
2688
        // to load the fields...
2689
1.85k
        clang::ExternalASTSource *external_ast_source =
2690
1.85k
            ast->getExternalSource();
2691
1.85k
        if (external_ast_source) {
2692
1.85k
          external_ast_source->CompleteType(cxx_record_decl);
2693
1.85k
          if (cxx_record_decl->isCompleteDefinition()) {
2694
1.84k
            cxx_record_decl->field_begin();
2695
1.84k
            cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
2696
1.84k
          }
2697
1.85k
        }
2698
1.85k
      }
2699
256k
    }
2700
242k
    const clang::TagType *tag_type =
2701
242k
        llvm::cast<clang::TagType>(qual_type.getTypePtr());
2702
242k
    return !tag_type->isIncompleteType();
2703
256k
  } 
break0
;
2704
2705
2.03k
  case clang::Type::Enum: {
2706
2.03k
    const clang::TagType *tag_type =
2707
2.03k
        llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
2708
2.03k
    if (tag_type) {
2709
2.03k
      clang::TagDecl *tag_decl = tag_type->getDecl();
2710
2.03k
      if (tag_decl) {
2711
2.03k
        if (tag_decl->getDefinition())
2712
2.03k
          return true;
2713
2714
0
        if (!allow_completion)
2715
0
          return false;
2716
2717
0
        if (tag_decl->hasExternalLexicalStorage()) {
2718
0
          if (ast) {
2719
0
            clang::ExternalASTSource *external_ast_source =
2720
0
                ast->getExternalSource();
2721
0
            if (external_ast_source) {
2722
0
              external_ast_source->CompleteType(tag_decl);
2723
0
              return !tag_type->isIncompleteType();
2724
0
            }
2725
0
          }
2726
0
        }
2727
0
        return false;
2728
0
      }
2729
2.03k
    }
2730
2731
2.03k
  } 
break0
;
2732
999
  case clang::Type::ObjCObject:
2733
6.17k
  case clang::Type::ObjCInterface: {
2734
6.17k
    const clang::ObjCObjectType *objc_class_type =
2735
6.17k
        llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2736
6.17k
    if (objc_class_type) {
2737
6.17k
      clang::ObjCInterfaceDecl *class_interface_decl =
2738
6.17k
          objc_class_type->getInterface();
2739
      // We currently can't complete objective C types through the newly added
2740
      // ASTContext because it only supports TagDecl objects right now...
2741
6.17k
      if (class_interface_decl) {
2742
5.17k
        if (class_interface_decl->getDefinition())
2743
5.08k
          return true;
2744
2745
93
        if (!allow_completion)
2746
0
          return false;
2747
2748
93
        if (class_interface_decl->hasExternalLexicalStorage()) {
2749
93
          if (ast) {
2750
93
            clang::ExternalASTSource *external_ast_source =
2751
93
                ast->getExternalSource();
2752
93
            if (external_ast_source) {
2753
93
              external_ast_source->CompleteType(class_interface_decl);
2754
93
              return !objc_class_type->isIncompleteType();
2755
93
            }
2756
93
          }
2757
93
        }
2758
0
        return false;
2759
93
      }
2760
6.17k
    }
2761
6.17k
  } 
break999
;
2762
2763
999
  case clang::Type::Attributed:
2764
175
    return GetCompleteQualType(
2765
175
        ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2766
175
        allow_completion);
2767
2768
565k
  default:
2769
565k
    break;
2770
833k
  }
2771
2772
566k
  return true;
2773
833k
}
2774
2775
static clang::ObjCIvarDecl::AccessControl
2776
713
ConvertAccessTypeToObjCIvarAccessControl(AccessType access) {
2777
713
  switch (access) {
2778
0
  case eAccessNone:
2779
0
    return clang::ObjCIvarDecl::None;
2780
713
  case eAccessPublic:
2781
713
    return clang::ObjCIvarDecl::Public;
2782
0
  case eAccessPrivate:
2783
0
    return clang::ObjCIvarDecl::Private;
2784
0
  case eAccessProtected:
2785
0
    return clang::ObjCIvarDecl::Protected;
2786
0
  case eAccessPackage:
2787
0
    return clang::ObjCIvarDecl::Package;
2788
713
  }
2789
0
  return clang::ObjCIvarDecl::None;
2790
713
}
2791
2792
// Tests
2793
2794
#ifndef NDEBUG
2795
932k
bool TypeSystemClang::Verify(lldb::opaque_compiler_type_t type) {
2796
932k
  return !type || llvm::isa<clang::Type>(GetQualType(type).getTypePtr());
2797
932k
}
2798
#endif
2799
2800
201k
bool TypeSystemClang::IsAggregateType(lldb::opaque_compiler_type_t type) {
2801
201k
  clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2802
2803
201k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2804
201k
  switch (type_class) {
2805
6
  case clang::Type::IncompleteArray:
2806
6
  case clang::Type::VariableArray:
2807
1.49k
  case clang::Type::ConstantArray:
2808
1.49k
  case clang::Type::ExtVector:
2809
1.49k
  case clang::Type::Vector:
2810
87.4k
  case clang::Type::Record:
2811
88.4k
  case clang::Type::ObjCObject:
2812
89.5k
  case clang::Type::ObjCInterface:
2813
89.5k
    return true;
2814
111k
  default:
2815
111k
    break;
2816
201k
  }
2817
  // The clang type does have a value
2818
111k
  return false;
2819
201k
}
2820
2821
12
bool TypeSystemClang::IsAnonymousType(lldb::opaque_compiler_type_t type) {
2822
12
  clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2823
2824
12
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2825
12
  switch (type_class) {
2826
12
  case clang::Type::Record: {
2827
12
    if (const clang::RecordType *record_type =
2828
12
            llvm::dyn_cast_or_null<clang::RecordType>(
2829
12
                qual_type.getTypePtrOrNull())) {
2830
12
      if (const clang::RecordDecl *record_decl = record_type->getDecl()) {
2831
12
        return record_decl->isAnonymousStructOrUnion();
2832
12
      }
2833
12
    }
2834
0
    break;
2835
12
  }
2836
0
  default:
2837
0
    break;
2838
12
  }
2839
  // The clang type does have a value
2840
0
  return false;
2841
12
}
2842
2843
bool TypeSystemClang::IsArrayType(lldb::opaque_compiler_type_t type,
2844
                                  CompilerType *element_type_ptr,
2845
60.4k
                                  uint64_t *size, bool *is_incomplete) {
2846
60.4k
  clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2847
2848
60.4k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2849
60.4k
  switch (type_class) {
2850
46.5k
  default:
2851
46.5k
    break;
2852
2853
46.5k
  case clang::Type::ConstantArray:
2854
13.7k
    if (element_type_ptr)
2855
10.6k
      element_type_ptr->SetCompilerType(
2856
10.6k
          this, llvm::cast<clang::ConstantArrayType>(qual_type)
2857
10.6k
                    ->getElementType()
2858
10.6k
                    .getAsOpaquePtr());
2859
13.7k
    if (size)
2860
2.74k
      *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2861
2.74k
                  ->getSize()
2862
2.74k
                  .getLimitedValue(ULLONG_MAX);
2863
13.7k
    if (is_incomplete)
2864
978
      *is_incomplete = false;
2865
13.7k
    return true;
2866
2867
91
  case clang::Type::IncompleteArray:
2868
91
    if (element_type_ptr)
2869
39
      element_type_ptr->SetCompilerType(
2870
39
          this, llvm::cast<clang::IncompleteArrayType>(qual_type)
2871
39
                    ->getElementType()
2872
39
                    .getAsOpaquePtr());
2873
91
    if (size)
2874
37
      *size = 0;
2875
91
    if (is_incomplete)
2876
39
      *is_incomplete = true;
2877
91
    return true;
2878
2879
0
  case clang::Type::VariableArray:
2880
0
    if (element_type_ptr)
2881
0
      element_type_ptr->SetCompilerType(
2882
0
          this, llvm::cast<clang::VariableArrayType>(qual_type)
2883
0
                    ->getElementType()
2884
0
                    .getAsOpaquePtr());
2885
0
    if (size)
2886
0
      *size = 0;
2887
0
    if (is_incomplete)
2888
0
      *is_incomplete = false;
2889
0
    return true;
2890
2891
0
  case clang::Type::DependentSizedArray:
2892
0
    if (element_type_ptr)
2893
0
      element_type_ptr->SetCompilerType(
2894
0
          this, llvm::cast<clang::DependentSizedArrayType>(qual_type)
2895
0
                    ->getElementType()
2896
0
                    .getAsOpaquePtr());
2897
0
    if (size)
2898
0
      *size = 0;
2899
0
    if (is_incomplete)
2900
0
      *is_incomplete = false;
2901
0
    return true;
2902
60.4k
  }
2903
46.5k
  if (element_type_ptr)
2904
9.35k
    element_type_ptr->Clear();
2905
46.5k
  if (size)
2906
43.8k
    *size = 0;
2907
46.5k
  if (is_incomplete)
2908
9.18k
    *is_incomplete = false;
2909
46.5k
  return false;
2910
60.4k
}
2911
2912
bool TypeSystemClang::IsVectorType(lldb::opaque_compiler_type_t type,
2913
160k
                                   CompilerType *element_type, uint64_t *size) {
2914
160k
  clang::QualType qual_type(GetCanonicalQualType(type));
2915
2916
160k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2917
160k
  switch (type_class) {
2918
0
  case clang::Type::Vector: {
2919
0
    const clang::VectorType *vector_type =
2920
0
        qual_type->getAs<clang::VectorType>();
2921
0
    if (vector_type) {
2922
0
      if (size)
2923
0
        *size = vector_type->getNumElements();
2924
0
      if (element_type)
2925
0
        *element_type = GetType(vector_type->getElementType());
2926
0
    }
2927
0
    return true;
2928
0
  } break;
2929
2.19k
  case clang::Type::ExtVector: {
2930
2.19k
    const clang::ExtVectorType *ext_vector_type =
2931
2.19k
        qual_type->getAs<clang::ExtVectorType>();
2932
2.19k
    if (ext_vector_type) {
2933
2.19k
      if (size)
2934
0
        *size = ext_vector_type->getNumElements();
2935
2.19k
      if (element_type)
2936
468
        *element_type =
2937
468
            CompilerType(this, ext_vector_type->getElementType().getAsOpaquePtr());
2938
2.19k
    }
2939
2.19k
    return true;
2940
0
  }
2941
158k
  default:
2942
158k
    break;
2943
160k
  }
2944
158k
  return false;
2945
160k
}
2946
2947
bool TypeSystemClang::IsRuntimeGeneratedType(
2948
0
    lldb::opaque_compiler_type_t type) {
2949
0
  clang::DeclContext *decl_ctx = GetDeclContextForType(GetQualType(type));
2950
0
  if (!decl_ctx)
2951
0
    return false;
2952
2953
0
  if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2954
0
    return false;
2955
2956
0
  clang::ObjCInterfaceDecl *result_iface_decl =
2957
0
      llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2958
2959
0
  ClangASTMetadata *ast_metadata = GetMetadata(result_iface_decl);
2960
0
  if (!ast_metadata)
2961
0
    return false;
2962
0
  return (ast_metadata->GetISAPtr() != 0);
2963
0
}
2964
2965
6.82k
bool TypeSystemClang::IsCharType(lldb::opaque_compiler_type_t type) {
2966
6.82k
  return GetQualType(type).getUnqualifiedType()->isCharType();
2967
6.82k
}
2968
2969
13.1k
bool TypeSystemClang::IsCompleteType(lldb::opaque_compiler_type_t type) {
2970
  // If the type hasn't been lazily completed yet, complete it now so that we
2971
  // can give the caller an accurate answer whether the type actually has a
2972
  // definition. Without completing the type now we would just tell the user
2973
  // the current (internal) completeness state of the type and most users don't
2974
  // care (or even know) about this behavior.
2975
13.1k
  const bool allow_completion = true;
2976
13.1k
  return GetCompleteQualType(&getASTContext(), GetQualType(type),
2977
13.1k
                             allow_completion);
2978
13.1k
}
2979
2980
0
bool TypeSystemClang::IsConst(lldb::opaque_compiler_type_t type) {
2981
0
  return GetQualType(type).isConstQualified();
2982
0
}
2983
2984
bool TypeSystemClang::IsCStringType(lldb::opaque_compiler_type_t type,
2985
0
                                    uint32_t &length) {
2986
0
  CompilerType pointee_or_element_clang_type;
2987
0
  length = 0;
2988
0
  Flags type_flags(GetTypeInfo(type, &pointee_or_element_clang_type));
2989
2990
0
  if (!pointee_or_element_clang_type.IsValid())
2991
0
    return false;
2992
2993
0
  if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer)) {
2994
0
    if (pointee_or_element_clang_type.IsCharType()) {
2995
0
      if (type_flags.Test(eTypeIsArray)) {
2996
        // We know the size of the array and it could be a C string since it is
2997
        // an array of characters
2998
0
        length = llvm::cast<clang::ConstantArrayType>(
2999
0
                     GetCanonicalQualType(type).getTypePtr())
3000
0
                     ->getSize()
3001
0
                     .getLimitedValue();
3002
0
      }
3003
0
      return true;
3004
0
    }
3005
0
  }
3006
0
  return false;
3007
0
}
3008
3009
6
bool TypeSystemClang::IsFunctionType(lldb::opaque_compiler_type_t type) {
3010
6
  if (type) {
3011
6
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3012
3013
6
    if (qual_type->isFunctionType()) {
3014
6
      return true;
3015
6
    }
3016
3017
0
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3018
0
    switch (type_class) {
3019
0
    default:
3020
0
      break;
3021
0
    case clang::Type::LValueReference:
3022
0
    case clang::Type::RValueReference: {
3023
0
      const clang::ReferenceType *reference_type =
3024
0
          llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3025
0
      if (reference_type)
3026
0
        return IsFunctionType(
3027
0
            reference_type->getPointeeType().getAsOpaquePtr());
3028
0
    } break;
3029
0
    }
3030
0
  }
3031
0
  return false;
3032
6
}
3033
3034
// Used to detect "Homogeneous Floating-point Aggregates"
3035
uint32_t
3036
TypeSystemClang::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
3037
0
                                        CompilerType *base_type_ptr) {
3038
0
  if (!type)
3039
0
    return 0;
3040
3041
0
  clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
3042
0
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3043
0
  switch (type_class) {
3044
0
  case clang::Type::Record:
3045
0
    if (GetCompleteType(type)) {
3046
0
      const clang::CXXRecordDecl *cxx_record_decl =
3047
0
          qual_type->getAsCXXRecordDecl();
3048
0
      if (cxx_record_decl) {
3049
0
        if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3050
0
          return 0;
3051
0
      }
3052
0
      const clang::RecordType *record_type =
3053
0
          llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3054
0
      if (record_type) {
3055
0
        const clang::RecordDecl *record_decl = record_type->getDecl();
3056
0
        if (record_decl) {
3057
          // We are looking for a structure that contains only floating point
3058
          // types
3059
0
          clang::RecordDecl::field_iterator field_pos,
3060
0
              field_end = record_decl->field_end();
3061
0
          uint32_t num_fields = 0;
3062
0
          bool is_hva = false;
3063
0
          bool is_hfa = false;
3064
0
          clang::QualType base_qual_type;
3065
0
          uint64_t base_bitwidth = 0;
3066
0
          for (field_pos = record_decl->field_begin(); field_pos != field_end;
3067
0
               ++field_pos) {
3068
0
            clang::QualType field_qual_type = field_pos->getType();
3069
0
            uint64_t field_bitwidth = getASTContext().getTypeSize(qual_type);
3070
0
            if (field_qual_type->isFloatingType()) {
3071
0
              if (field_qual_type->isComplexType())
3072
0
                return 0;
3073
0
              else {
3074
0
                if (num_fields == 0)
3075
0
                  base_qual_type = field_qual_type;
3076
0
                else {
3077
0
                  if (is_hva)
3078
0
                    return 0;
3079
0
                  is_hfa = true;
3080
0
                  if (field_qual_type.getTypePtr() !=
3081
0
                      base_qual_type.getTypePtr())
3082
0
                    return 0;
3083
0
                }
3084
0
              }
3085
0
            } else if (field_qual_type->isVectorType() ||
3086
0
                       field_qual_type->isExtVectorType()) {
3087
0
              if (num_fields == 0) {
3088
0
                base_qual_type = field_qual_type;
3089
0
                base_bitwidth = field_bitwidth;
3090
0
              } else {
3091
0
                if (is_hfa)
3092
0
                  return 0;
3093
0
                is_hva = true;
3094
0
                if (base_bitwidth != field_bitwidth)
3095
0
                  return 0;
3096
0
                if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3097
0
                  return 0;
3098
0
              }
3099
0
            } else
3100
0
              return 0;
3101
0
            ++num_fields;
3102
0
          }
3103
0
          if (base_type_ptr)
3104
0
            *base_type_ptr = CompilerType(this, base_qual_type.getAsOpaquePtr());
3105
0
          return num_fields;
3106
0
        }
3107
0
      }
3108
0
    }
3109
0
    break;
3110
3111
0
  default:
3112
0
    break;
3113
0
  }
3114
0
  return 0;
3115
0
}
3116
3117
size_t TypeSystemClang::GetNumberOfFunctionArguments(
3118
9
    lldb::opaque_compiler_type_t type) {
3119
9
  if (type) {
3120
9
    clang::QualType qual_type(GetCanonicalQualType(type));
3121
9
    const clang::FunctionProtoType *func =
3122
9
        llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3123
9
    if (func)
3124
9
      return func->getNumParams();
3125
9
  }
3126
0
  return 0;
3127
9
}
3128
3129
CompilerType
3130
TypeSystemClang::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
3131
15
                                            const size_t index) {
3132
15
  if (type) {
3133
15
    clang::QualType qual_type(GetQualType(type));
3134
15
    const clang::FunctionProtoType *func =
3135
15
        llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3136
15
    if (func) {
3137
15
      if (index < func->getNumParams())
3138
15
        return CompilerType(this, func->getParamType(index).getAsOpaquePtr());
3139
15
    }
3140
15
  }
3141
0
  return CompilerType();
3142
15
}
3143
3144
79.1k
bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
3145
79.1k
  if (type) {
3146
79.1k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3147
3148
79.1k
    if (qual_type->isFunctionPointerType())
3149
135
      return true;
3150
3151
79.0k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3152
79.0k
    switch (type_class) {
3153
78.0k
    default:
3154
78.0k
      break;
3155
3156
78.0k
    case clang::Type::LValueReference:
3157
973
    case clang::Type::RValueReference: {
3158
973
      const clang::ReferenceType *reference_type =
3159
973
          llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3160
973
      if (reference_type)
3161
973
        return IsFunctionPointerType(
3162
973
            reference_type->getPointeeType().getAsOpaquePtr());
3163
973
    } 
break0
;
3164
79.0k
    }
3165
79.0k
  }
3166
78.0k
  return false;
3167
79.1k
}
3168
3169
bool TypeSystemClang::IsBlockPointerType(
3170
    lldb::opaque_compiler_type_t type,
3171
160k
    CompilerType *function_pointer_type_ptr) {
3172
160k
  if (type) {
3173
160k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3174
3175
160k
    if (qual_type->isBlockPointerType()) {
3176
36
      if (function_pointer_type_ptr) {
3177
12
        const clang::BlockPointerType *block_pointer_type =
3178
12
            qual_type->getAs<clang::BlockPointerType>();
3179
12
        QualType pointee_type = block_pointer_type->getPointeeType();
3180
12
        QualType function_pointer_type = m_ast_up->getPointerType(pointee_type);
3181
12
        *function_pointer_type_ptr =
3182
12
            CompilerType(this, function_pointer_type.getAsOpaquePtr());
3183
12
      }
3184
36
      return true;
3185
36
    }
3186
3187
160k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3188
160k
    switch (type_class) {
3189
158k
    default:
3190
158k
      break;
3191
3192
158k
    case clang::Type::LValueReference:
3193
1.91k
    case clang::Type::RValueReference: {
3194
1.91k
      const clang::ReferenceType *reference_type =
3195
1.91k
          llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3196
1.91k
      if (reference_type)
3197
1.91k
        return IsBlockPointerType(
3198
1.91k
            reference_type->getPointeeType().getAsOpaquePtr(),
3199
1.91k
            function_pointer_type_ptr);
3200
1.91k
    } 
break0
;
3201
160k
    }
3202
160k
  }
3203
158k
  return false;
3204
160k
}
3205
3206
bool TypeSystemClang::IsIntegerType(lldb::opaque_compiler_type_t type,
3207
26.8k
                                    bool &is_signed) {
3208
26.8k
  if (!type)
3209
0
    return false;
3210
3211
26.8k
  clang::QualType qual_type(GetCanonicalQualType(type));
3212
26.8k
  const clang::BuiltinType *builtin_type =
3213
26.8k
      llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3214
3215
26.8k
  if (builtin_type) {
3216
14.1k
    if (builtin_type->isInteger()) {
3217
13.4k
      is_signed = builtin_type->isSignedInteger();
3218
13.4k
      return true;
3219
13.4k
    }
3220
14.1k
  }
3221
3222
13.4k
  return false;
3223
26.8k
}
3224
3225
bool TypeSystemClang::IsEnumerationType(lldb::opaque_compiler_type_t type,
3226
13.1k
                                        bool &is_signed) {
3227
13.1k
  if (type) {
3228
13.1k
    const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3229
13.1k
        GetCanonicalQualType(type)->getCanonicalTypeInternal());
3230
3231
13.1k
    if (enum_type) {
3232
81
      IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3233
81
                    is_signed);
3234
81
      return true;
3235
81
    }
3236
13.1k
  }
3237
3238
13.0k
  return false;
3239
13.1k
}
3240
3241
bool TypeSystemClang::IsScopedEnumerationType(
3242
0
    lldb::opaque_compiler_type_t type) {
3243
0
  if (type) {
3244
0
    const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3245
0
        GetCanonicalQualType(type)->getCanonicalTypeInternal());
3246
3247
0
    if (enum_type) {
3248
0
      return enum_type->isScopedEnumeralType();
3249
0
    }
3250
0
  }
3251
3252
0
  return false;
3253
0
}
3254
3255
bool TypeSystemClang::IsPointerType(lldb::opaque_compiler_type_t type,
3256
60.2k
                                    CompilerType *pointee_type) {
3257
60.2k
  if (type) {
3258
60.2k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3259
60.2k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3260
60.2k
    switch (type_class) {
3261
10.9k
    case clang::Type::Builtin:
3262
10.9k
      switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3263
10.8k
      default:
3264
10.8k
        break;
3265
10.8k
      case clang::BuiltinType::ObjCId:
3266
75
      case clang::BuiltinType::ObjCClass:
3267
75
        return true;
3268
10.9k
      }
3269
10.8k
      return false;
3270
2.65k
    case clang::Type::ObjCObjectPointer:
3271
2.65k
      if (pointee_type)
3272
0
        pointee_type->SetCompilerType(
3273
0
            this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3274
0
                      ->getPointeeType()
3275
0
                      .getAsOpaquePtr());
3276
2.65k
      return true;
3277
3
    case clang::Type::BlockPointer:
3278
3
      if (pointee_type)
3279
0
        pointee_type->SetCompilerType(
3280
0
            this, llvm::cast<clang::BlockPointerType>(qual_type)
3281
0
                      ->getPointeeType()
3282
0
                      .getAsOpaquePtr());
3283
3
      return true;
3284
13.1k
    case clang::Type::Pointer:
3285
13.1k
      if (pointee_type)
3286
63
        pointee_type->SetCompilerType(this,
3287
63
                                      llvm::cast<clang::PointerType>(qual_type)
3288
63
                                          ->getPointeeType()
3289
63
                                          .getAsOpaquePtr());
3290
13.1k
      return true;
3291
3
    case clang::Type::MemberPointer:
3292
3
      if (pointee_type)
3293
0
        pointee_type->SetCompilerType(
3294
0
            this, llvm::cast<clang::MemberPointerType>(qual_type)
3295
0
                      ->getPointeeType()
3296
0
                      .getAsOpaquePtr());
3297
3
      return true;
3298
33.4k
    default:
3299
33.4k
      break;
3300
60.2k
    }
3301
60.2k
  }
3302
33.4k
  if (pointee_type)
3303
0
    pointee_type->Clear();
3304
33.4k
  return false;
3305
60.2k
}
3306
3307
bool TypeSystemClang::IsPointerOrReferenceType(
3308
58.4k
    lldb::opaque_compiler_type_t type, CompilerType *pointee_type) {
3309
58.4k
  if (type) {
3310
58.4k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3311
58.4k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3312
58.4k
    switch (type_class) {
3313
233
    case clang::Type::Builtin:
3314
233
      switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3315
200
      default:
3316
200
        break;
3317
200
      case clang::BuiltinType::ObjCId:
3318
33
      case clang::BuiltinType::ObjCClass:
3319
33
        return true;
3320
233
      }
3321
200
      return false;
3322
821
    case clang::Type::ObjCObjectPointer:
3323
821
      if (pointee_type)
3324
0
        pointee_type->SetCompilerType(
3325
0
            this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3326
0
                                 ->getPointeeType().getAsOpaquePtr());
3327
821
      return true;
3328
0
    case clang::Type::BlockPointer:
3329
0
      if (pointee_type)
3330
0
        pointee_type->SetCompilerType(
3331
0
            this, llvm::cast<clang::BlockPointerType>(qual_type)
3332
0
                      ->getPointeeType()
3333
0
                      .getAsOpaquePtr());
3334
0
      return true;
3335
28.8k
    case clang::Type::Pointer:
3336
28.8k
      if (pointee_type)
3337
0
        pointee_type->SetCompilerType(this,
3338
0
                                      llvm::cast<clang::PointerType>(qual_type)
3339
0
                                          ->getPointeeType()
3340
0
                                          .getAsOpaquePtr());
3341
28.8k
      return true;
3342
0
    case clang::Type::MemberPointer:
3343
0
      if (pointee_type)
3344
0
        pointee_type->SetCompilerType(
3345
0
            this, llvm::cast<clang::MemberPointerType>(qual_type)
3346
0
                      ->getPointeeType()
3347
0
                      .getAsOpaquePtr());
3348
0
      return true;
3349
761
    case clang::Type::LValueReference:
3350
761
      if (pointee_type)
3351
0
        pointee_type->SetCompilerType(
3352
0
            this, llvm::cast<clang::LValueReferenceType>(qual_type)
3353
0
                      ->desugar()
3354
0
                      .getAsOpaquePtr());
3355
761
      return true;
3356
21
    case clang::Type::RValueReference:
3357
21
      if (pointee_type)
3358
0
        pointee_type->SetCompilerType(
3359
0
            this, llvm::cast<clang::RValueReferenceType>(qual_type)
3360
0
                      ->desugar()
3361
0
                      .getAsOpaquePtr());
3362
21
      return true;
3363
27.6k
    default:
3364
27.6k
      break;
3365
58.4k
    }
3366
58.4k
  }
3367
27.6k
  if (pointee_type)
3368
0
    pointee_type->Clear();
3369
27.6k
  return false;
3370
58.4k
}
3371
3372
bool TypeSystemClang::IsReferenceType(lldb::opaque_compiler_type_t type,
3373
                                      CompilerType *pointee_type,
3374
63.5k
                                      bool *is_rvalue) {
3375
63.5k
  if (type) {
3376
63.5k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3377
63.5k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3378
3379
63.5k
    switch (type_class) {
3380
3.03k
    case clang::Type::LValueReference:
3381
3.03k
      if (pointee_type)
3382
0
        pointee_type->SetCompilerType(
3383
0
            this, llvm::cast<clang::LValueReferenceType>(qual_type)
3384
0
                      ->desugar()
3385
0
                      .getAsOpaquePtr());
3386
3.03k
      if (is_rvalue)
3387
543
        *is_rvalue = false;
3388
3.03k
      return true;
3389
82
    case clang::Type::RValueReference:
3390
82
      if (pointee_type)
3391
0
        pointee_type->SetCompilerType(
3392
0
            this, llvm::cast<clang::RValueReferenceType>(qual_type)
3393
0
                      ->desugar()
3394
0
                      .getAsOpaquePtr());
3395
82
      if (is_rvalue)
3396
73
        *is_rvalue = true;
3397
82
      return true;
3398
3399
60.4k
    default:
3400
60.4k
      break;
3401
63.5k
    }
3402
63.5k
  }
3403
60.4k
  if (pointee_type)
3404
0
    pointee_type->Clear();
3405
60.4k
  return false;
3406
63.5k
}
3407
3408
bool TypeSystemClang::IsFloatingPointType(lldb::opaque_compiler_type_t type,
3409
165
                                          uint32_t &count, bool &is_complex) {
3410
165
  if (type) {
3411
165
    clang::QualType qual_type(GetCanonicalQualType(type));
3412
3413
165
    if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3414
165
            qual_type->getCanonicalTypeInternal())) {
3415
132
      clang::BuiltinType::Kind kind = BT->getKind();
3416
132
      if (kind >= clang::BuiltinType::Float &&
3417
132
          kind <= clang::BuiltinType::LongDouble) {
3418
132
        count = 1;
3419
132
        is_complex = false;
3420
132
        return true;
3421
132
      }
3422
132
    } else 
if (const clang::ComplexType *33
CT33
=
3423
33
                   llvm::dyn_cast<clang::ComplexType>(
3424
33
                       qual_type->getCanonicalTypeInternal())) {
3425
0
      if (IsFloatingPointType(CT->getElementType().getAsOpaquePtr(), count,
3426
0
                              is_complex)) {
3427
0
        count = 2;
3428
0
        is_complex = true;
3429
0
        return true;
3430
0
      }
3431
33
    } else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3432
33
                   qual_type->getCanonicalTypeInternal())) {
3433
0
      if (IsFloatingPointType(VT->getElementType().getAsOpaquePtr(), count,
3434
0
                              is_complex)) {
3435
0
        count = VT->getNumElements();
3436
0
        is_complex = false;
3437
0
        return true;
3438
0
      }
3439
0
    }
3440
165
  }
3441
33
  count = 0;
3442
33
  is_complex = false;
3443
33
  return false;
3444
165
}
3445
3446
12.1k
bool TypeSystemClang::IsDefined(lldb::opaque_compiler_type_t type) {
3447
12.1k
  if (!type)
3448
0
    return false;
3449
3450
12.1k
  clang::QualType qual_type(GetQualType(type));
3451
12.1k
  const clang::TagType *tag_type =
3452
12.1k
      llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3453
12.1k
  if (tag_type) {
3454
5.74k
    clang::TagDecl *tag_decl = tag_type->getDecl();
3455
5.74k
    if (tag_decl)
3456
5.74k
      return tag_decl->isCompleteDefinition();
3457
0
    return false;
3458
6.42k
  } else {
3459
6.42k
    const clang::ObjCObjectType *objc_class_type =
3460
6.42k
        llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3461
6.42k
    if (objc_class_type) {
3462
1.02k
      clang::ObjCInterfaceDecl *class_interface_decl =
3463
1.02k
          objc_class_type->getInterface();
3464
1.02k
      if (class_interface_decl)
3465
1.02k
        return class_interface_decl->getDefinition() != nullptr;
3466
0
      return false;
3467
1.02k
    }
3468
6.42k
  }
3469
5.40k
  return true;
3470
12.1k
}
3471
3472
15
bool TypeSystemClang::IsObjCClassType(const CompilerType &type) {
3473
15
  if (ClangUtil::IsClangType(type)) {
3474
15
    clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3475
3476
15
    const clang::ObjCObjectPointerType *obj_pointer_type =
3477
15
        llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3478
3479
15
    if (obj_pointer_type)
3480
15
      return obj_pointer_type->isObjCClassType();
3481
15
  }
3482
0
  return false;
3483
15
}
3484
3485
21.9k
bool TypeSystemClang::IsObjCObjectOrInterfaceType(const CompilerType &type) {
3486
21.9k
  if (ClangUtil::IsClangType(type))
3487
21.9k
    return ClangUtil::GetCanonicalQualType(type)->isObjCObjectOrInterfaceType();
3488
0
  return false;
3489
21.9k
}
3490
3491
0
bool TypeSystemClang::IsClassType(lldb::opaque_compiler_type_t type) {
3492
0
  if (!type)
3493
0
    return false;
3494
0
  clang::QualType qual_type(GetCanonicalQualType(type));
3495
0
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3496
0
  return (type_class == clang::Type::Record);
3497
0
}
3498
3499
0
bool TypeSystemClang::IsEnumType(lldb::opaque_compiler_type_t type) {
3500
0
  if (!type)
3501
0
    return false;
3502
0
  clang::QualType qual_type(GetCanonicalQualType(type));
3503
0
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3504
0
  return (type_class == clang::Type::Enum);
3505
0
}
3506
3507
0
bool TypeSystemClang::IsPolymorphicClass(lldb::opaque_compiler_type_t type) {
3508
0
  if (type) {
3509
0
    clang::QualType qual_type(GetCanonicalQualType(type));
3510
0
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3511
0
    switch (type_class) {
3512
0
    case clang::Type::Record:
3513
0
      if (GetCompleteType(type)) {
3514
0
        const clang::RecordType *record_type =
3515
0
            llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3516
0
        const clang::RecordDecl *record_decl = record_type->getDecl();
3517
0
        if (record_decl) {
3518
0
          const clang::CXXRecordDecl *cxx_record_decl =
3519
0
              llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3520
0
          if (cxx_record_decl)
3521
0
            return cxx_record_decl->isPolymorphic();
3522
0
        }
3523
0
      }
3524
0
      break;
3525
3526
0
    default:
3527
0
      break;
3528
0
    }
3529
0
  }
3530
0
  return false;
3531
0
}
3532
3533
bool TypeSystemClang::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
3534
                                            CompilerType *dynamic_pointee_type,
3535
                                            bool check_cplusplus,
3536
171k
                                            bool check_objc) {
3537
171k
  clang::QualType pointee_qual_type;
3538
171k
  if (type) {
3539
171k
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3540
171k
    bool success = false;
3541
171k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3542
171k
    switch (type_class) {
3543
1.15k
    case clang::Type::Builtin:
3544
1.15k
      if (check_objc &&
3545
1.15k
          llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3546
750
              clang::BuiltinType::ObjCId) {
3547
372
        if (dynamic_pointee_type)
3548
0
          dynamic_pointee_type->SetCompilerType(this, type);
3549
372
        return true;
3550
372
      }
3551
780
      break;
3552
3553
4.42k
    case clang::Type::ObjCObjectPointer:
3554
4.42k
      if (check_objc) {
3555
4.42k
        if (const auto *objc_pointee_type =
3556
4.42k
                qual_type->getPointeeType().getTypePtrOrNull()) {
3557
4.42k
          if (const auto *objc_object_type =
3558
4.42k
                  llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3559
4.42k
                      objc_pointee_type)) {
3560
4.42k
            if (objc_object_type->isObjCClass())
3561
537
              return false;
3562
4.42k
          }
3563
4.42k
        }
3564
3.88k
        if (dynamic_pointee_type)
3565
0
          dynamic_pointee_type->SetCompilerType(
3566
0
              this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3567
0
                        ->getPointeeType()
3568
0
                        .getAsOpaquePtr());
3569
3.88k
        return true;
3570
4.42k
      }
3571
0
      break;
3572
3573
46.5k
    case clang::Type::Pointer:
3574
46.5k
      pointee_qual_type =
3575
46.5k
          llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3576
46.5k
      success = true;
3577
46.5k
      break;
3578
3579
2.57k
    case clang::Type::LValueReference:
3580
2.90k
    case clang::Type::RValueReference:
3581
2.90k
      pointee_qual_type =
3582
2.90k
          llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3583
2.90k
      success = true;
3584
2.90k
      break;
3585
3586
116k
    default:
3587
116k
      break;
3588
171k
    }
3589
3590
166k
    if (success) {
3591
      // Check to make sure what we are pointing too is a possible dynamic C++
3592
      // type We currently accept any "void *" (in case we have a class that
3593
      // has been watered down to an opaque pointer) and virtual C++ classes.
3594
49.4k
      const clang::Type::TypeClass pointee_type_class =
3595
49.4k
          pointee_qual_type.getCanonicalType()->getTypeClass();
3596
49.4k
      switch (pointee_type_class) {
3597
1.56k
      case clang::Type::Builtin:
3598
1.56k
        switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3599
0
        case clang::BuiltinType::UnknownAny:
3600
419
        case clang::BuiltinType::Void:
3601
419
          if (dynamic_pointee_type)
3602
0
            dynamic_pointee_type->SetCompilerType(
3603
0
                this, pointee_qual_type.getAsOpaquePtr());
3604
419
          return true;
3605
1.15k
        default:
3606
1.15k
          break;
3607
1.56k
        }
3608
1.15k
        break;
3609
3610
47.5k
      case clang::Type::Record:
3611
47.5k
        if (check_cplusplus) {
3612
47.4k
          clang::CXXRecordDecl *cxx_record_decl =
3613
47.4k
              pointee_qual_type->getAsCXXRecordDecl();
3614
47.4k
          if (cxx_record_decl) {
3615
47.4k
            bool is_complete = cxx_record_decl->isCompleteDefinition();
3616
3617
47.4k
            if (is_complete)
3618
47.3k
              success = cxx_record_decl->isDynamicClass();
3619
120
            else {
3620
120
              ClangASTMetadata *metadata = GetMetadata(cxx_record_decl);
3621
120
              if (metadata)
3622
101
                success = metadata->GetIsDynamicCXXType();
3623
19
              else {
3624
19
                is_complete = GetType(pointee_qual_type).GetCompleteType();
3625
19
                if (is_complete)
3626
1
                  success = cxx_record_decl->isDynamicClass();
3627
18
                else
3628
18
                  success = false;
3629
19
              }
3630
120
            }
3631
3632
47.4k
            if (success) {
3633
584
              if (dynamic_pointee_type)
3634
0
                dynamic_pointee_type->SetCompilerType(
3635
0
                    this, pointee_qual_type.getAsOpaquePtr());
3636
584
              return true;
3637
584
            }
3638
47.4k
          }
3639
47.4k
        }
3640
46.9k
        break;
3641
3642
46.9k
      case clang::Type::ObjCObject:
3643
0
      case clang::Type::ObjCInterface:
3644
0
        if (check_objc) {
3645
0
          if (dynamic_pointee_type)
3646
0
            dynamic_pointee_type->SetCompilerType(
3647
0
                this, pointee_qual_type.getAsOpaquePtr());
3648
0
          return true;
3649
0
        }
3650
0
        break;
3651
3652
408
      default:
3653
408
        break;
3654
49.4k
      }
3655
49.4k
    }
3656
166k
  }
3657
165k
  if (dynamic_pointee_type)
3658
0
    dynamic_pointee_type->Clear();
3659
165k
  return false;
3660
171k
}
3661
3662
2.08k
bool TypeSystemClang::IsScalarType(lldb::opaque_compiler_type_t type) {
3663
2.08k
  if (!type)
3664
0
    return false;
3665
3666
2.08k
  return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
3667
2.08k
}
3668
3669
48.4k
bool TypeSystemClang::IsTypedefType(lldb::opaque_compiler_type_t type) {
3670
48.4k
  if (!type)
3671
0
    return false;
3672
48.4k
  return RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef})
3673
48.4k
             ->getTypeClass() == clang::Type::Typedef;
3674
48.4k
}
3675
3676
25.5k
bool TypeSystemClang::IsVoidType(lldb::opaque_compiler_type_t type) {
3677
25.5k
  if (!type)
3678
0
    return false;
3679
25.5k
  return GetCanonicalQualType(type)->isVoidType();
3680
25.5k
}
3681
3682
83
bool TypeSystemClang::CanPassInRegisters(const CompilerType &type) {
3683
83
  if (auto *record_decl =
3684
83
      TypeSystemClang::GetAsRecordDecl(type)) {
3685
83
    return record_decl->canPassInRegisters();
3686
83
  }
3687
0
  return false;
3688
83
}
3689
3690
3.09k
bool TypeSystemClang::SupportsLanguage(lldb::LanguageType language) {
3691
3.09k
  return TypeSystemClangSupportsLanguage(language);
3692
3.09k
}
3693
3694
Optional<std::string>
3695
0
TypeSystemClang::GetCXXClassName(const CompilerType &type) {
3696
0
  if (!type)
3697
0
    return llvm::None;
3698
3699
0
  clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3700
0
  if (qual_type.isNull())
3701
0
    return llvm::None;
3702
3703
0
  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3704
0
  if (!cxx_record_decl)
3705
0
    return llvm::None;
3706
3707
0
  return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3708
0
}
3709
3710
72.0k
bool TypeSystemClang::IsCXXClassType(const CompilerType &type) {
3711
72.0k
  if (!type)
3712
0
    return false;
3713
3714
72.0k
  clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3715
72.0k
  return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr;
3716
72.0k
}
3717
3718
60.1k
bool TypeSystemClang::IsBeingDefined(lldb::opaque_compiler_type_t type) {
3719
60.1k
  if (!type)
3720
0
    return false;
3721
60.1k
  clang::QualType qual_type(GetCanonicalQualType(type));
3722
60.1k
  const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3723
60.1k
  if (tag_type)
3724
60.1k
    return tag_type->isBeingDefined();
3725
0
  return false;
3726
60.1k
}
3727
3728
bool TypeSystemClang::IsObjCObjectPointerType(const CompilerType &type,
3729
7.02k
                                              CompilerType *class_type_ptr) {
3730
7.02k
  if (!ClangUtil::IsClangType(type))
3731
0
    return false;
3732
3733
7.02k
  clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3734
3735
7.02k
  if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3736
5.93k
    if (class_type_ptr) {
3737
5.92k
      if (!qual_type->isObjCClassType() && 
!qual_type->isObjCIdType()5.54k
) {
3738
4.14k
        const clang::ObjCObjectPointerType *obj_pointer_type =
3739
4.14k
            llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3740
4.14k
        if (obj_pointer_type == nullptr)
3741
0
          class_type_ptr->Clear();
3742
4.14k
        else
3743
4.14k
          class_type_ptr->SetCompilerType(
3744
4.14k
              type.GetTypeSystem(),
3745
4.14k
              clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3746
4.14k
                  .getAsOpaquePtr());
3747
4.14k
      }
3748
5.92k
    }
3749
5.93k
    return true;
3750
5.93k
  }
3751
1.08k
  if (class_type_ptr)
3752
1.08k
    class_type_ptr->Clear();
3753
1.08k
  return false;
3754
7.02k
}
3755
3756
// Type Completion
3757
3758
701k
bool TypeSystemClang::GetCompleteType(lldb::opaque_compiler_type_t type) {
3759
701k
  if (!type)
3760
0
    return false;
3761
701k
  const bool allow_completion = true;
3762
701k
  return GetCompleteQualType(&getASTContext(), GetQualType(type),
3763
701k
                             allow_completion);
3764
701k
}
3765
3766
377k
ConstString TypeSystemClang::GetTypeName(lldb::opaque_compiler_type_t type) {
3767
377k
  if (!type)
3768
0
    return ConstString();
3769
3770
377k
  clang::QualType qual_type(GetQualType(type));
3771
3772
  // Remove certain type sugar from the name. Sugar such as elaborated types
3773
  // or template types which only serve to improve diagnostics shouldn't
3774
  // act as their own types from the user's perspective (e.g., formatter
3775
  // shouldn't format a variable differently depending on how the ser has
3776
  // specified the type. '::Type' and 'Type' should behave the same).
3777
  // Typedefs and atomic derived types are not removed as they are actually
3778
  // useful for identifiying specific types.
3779
377k
  qual_type = RemoveWrappingTypes(qual_type,
3780
377k
                                  {clang::Type::Typedef, clang::Type::Atomic});
3781
3782
  // For a typedef just return the qualified name.
3783
377k
  if (const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3784
62.7k
    const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3785
62.7k
    return ConstString(GetTypeNameForDecl(typedef_decl));
3786
62.7k
  }
3787
3788
314k
  return ConstString(qual_type.getAsString(GetTypePrintingPolicy()));
3789
377k
}
3790
3791
ConstString
3792
40.1k
TypeSystemClang::GetDisplayTypeName(lldb::opaque_compiler_type_t type) {
3793
40.1k
  if (!type)
3794
0
    return ConstString();
3795
3796
40.1k
  clang::QualType qual_type(GetQualType(type));
3797
40.1k
  clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
3798
40.1k
  printing_policy.SuppressTagKeyword = true;
3799
40.1k
  printing_policy.SuppressScope = false;
3800
40.1k
  printing_policy.SuppressUnwrittenScope = true;
3801
40.1k
  printing_policy.SuppressInlineNamespace = true;
3802
40.1k
  return ConstString(qual_type.getAsString(printing_policy));
3803
40.1k
}
3804
3805
uint32_t
3806
TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,
3807
636k
                             CompilerType *pointee_or_element_clang_type) {
3808
636k
  if (!type)
3809
0
    return 0;
3810
3811
636k
  if (pointee_or_element_clang_type)
3812
12.3k
    pointee_or_element_clang_type->Clear();
3813
3814
636k
  clang::QualType qual_type =
3815
636k
      RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef});
3816
3817
636k
  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3818
636k
  switch (type_class) {
3819
71
  case clang::Type::Attributed:
3820
71
    return GetTypeInfo(
3821
71
        qual_type->getAs<clang::AttributedType>()
3822
71
            ->getModifiedType().getAsOpaquePtr(),
3823
71
        pointee_or_element_clang_type);
3824
214k
  case clang::Type::Builtin: {
3825
214k
    const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(
3826
214k
        qual_type->getCanonicalTypeInternal());
3827
3828
214k
    uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3829
214k
    switch (builtin_type->getKind()) {
3830
573
    case clang::BuiltinType::ObjCId:
3831
603
    case clang::BuiltinType::ObjCClass:
3832
603
      if (pointee_or_element_clang_type)
3833
0
        pointee_or_element_clang_type->SetCompilerType(
3834
0
            this, getASTContext().ObjCBuiltinClassTy.getAsOpaquePtr());
3835
603
      builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3836
603
      break;
3837
3838
18
    case clang::BuiltinType::ObjCSel:
3839
18
      if (pointee_or_element_clang_type)
3840
0
        pointee_or_element_clang_type->SetCompilerType(
3841
0
            this, getASTContext().CharTy.getAsOpaquePtr());
3842
18
      builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3843
18
      break;
3844
3845
63.3k
    case clang::BuiltinType::Bool:
3846
63.3k
    case clang::BuiltinType::Char_U:
3847
67.7k
    case clang::BuiltinType::UChar:
3848
67.7k
    case clang::BuiltinType::WChar_U:
3849
67.7k
    case clang::BuiltinType::Char16:
3850
67.8k
    case clang::BuiltinType::Char32:
3851
73.5k
    case clang::BuiltinType::UShort:
3852
79.4k
    case clang::BuiltinType::UInt:
3853
95.2k
    case clang::BuiltinType::ULong:
3854
97.5k
    case clang::BuiltinType::ULongLong:
3855
97.6k
    case clang::BuiltinType::UInt128:
3856
101k
    case clang::BuiltinType::Char_S:
3857
102k
    case clang::BuiltinType::SChar:
3858
102k
    case clang::BuiltinType::WChar_S:
3859
105k
    case clang::BuiltinType::Short:
3860
199k
    case clang::BuiltinType::Int:
3861
202k
    case clang::BuiltinType::Long:
3862
204k
    case clang::BuiltinType::LongLong:
3863
204k
    case clang::BuiltinType::Int128:
3864
209k
    case clang::BuiltinType::Float:
3865
213k
    case clang::BuiltinType::Double:
3866
213k
    case clang::BuiltinType::LongDouble:
3867
213k
      builtin_type_flags |= eTypeIsScalar;
3868
213k
      if (builtin_type->isInteger()) {
3869
204k
        builtin_type_flags |= eTypeIsInteger;
3870
204k
        if (builtin_type->isSignedInteger())
3871
107k
          builtin_type_flags |= eTypeIsSigned;
3872
204k
      } else 
if (8.79k
builtin_type->isFloatingPoint()8.79k
)
3873
8.79k
        builtin_type_flags |= eTypeIsFloat;
3874
213k
      break;
3875
190
    default:
3876
190
      break;
3877
214k
    }
3878
214k
    return builtin_type_flags;
3879
214k
  }
3880
3881
30
  case clang::Type::BlockPointer:
3882
30
    if (pointee_or_element_clang_type)
3883
0
      pointee_or_element_clang_type->SetCompilerType(
3884
0
          this, qual_type->getPointeeType().getAsOpaquePtr());
3885
30
    return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3886
3887
77
  case clang::Type::Complex: {
3888
77
    uint32_t complex_type_flags =
3889
77
        eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3890
77
    const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3891
77
        qual_type->getCanonicalTypeInternal());
3892
77
    if (complex_type) {
3893
77
      clang::QualType complex_element_type(complex_type->getElementType());
3894
77
      if (complex_element_type->isIntegerType())
3895
42
        complex_type_flags |= eTypeIsFloat;
3896
35
      else if (complex_element_type->isFloatingType())
3897
35
        complex_type_flags |= eTypeIsInteger;
3898
77
    }
3899
77
    return complex_type_flags;
3900
214k
  } 
break0
;
3901
3902
20.6k
  case clang::Type::ConstantArray:
3903
20.6k
  case clang::Type::DependentSizedArray:
3904
20.7k
  case clang::Type::IncompleteArray:
3905
20.7k
  case clang::Type::VariableArray:
3906
20.7k
    if (pointee_or_element_clang_type)
3907
6.65k
      pointee_or_element_clang_type->SetCompilerType(
3908
6.65k
          this, llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3909
6.65k
                    ->getElementType()
3910
6.65k
                    .getAsOpaquePtr());
3911
20.7k
    return eTypeHasChildren | eTypeIsArray;
3912
3913
0
  case clang::Type::DependentName:
3914
0
    return 0;
3915
0
  case clang::Type::DependentSizedExtVector:
3916
0
    return eTypeHasChildren | eTypeIsVector;
3917
0
  case clang::Type::DependentTemplateSpecialization:
3918
0
    return eTypeIsTemplate;
3919
3920
1.61k
  case clang::Type::Enum:
3921
1.61k
    if (pointee_or_element_clang_type)
3922
0
      pointee_or_element_clang_type->SetCompilerType(
3923
0
          this, llvm::cast<clang::EnumType>(qual_type)
3924
0
                    ->getDecl()
3925
0
                    ->getIntegerType()
3926
0
                    .getAsOpaquePtr());
3927
1.61k
    return eTypeIsEnumeration | eTypeHasValue;
3928
3929
60
  case clang::Type::FunctionProto:
3930
60
    return eTypeIsFuncPrototype | eTypeHasValue;
3931
0
  case clang::Type::FunctionNoProto:
3932
0
    return eTypeIsFuncPrototype | eTypeHasValue;
3933
0
  case clang::Type::InjectedClassName:
3934
0
    return 0;
3935
3936
6.70k
  case clang::Type::LValueReference:
3937
7.83k
  case clang::Type::RValueReference:
3938
7.83k
    if (pointee_or_element_clang_type)
3939
3
      pointee_or_element_clang_type->SetCompilerType(
3940
3
          this, llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3941
3
                    ->getPointeeType()
3942
3
                    .getAsOpaquePtr());
3943
7.83k
    return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3944
3945
5
  case clang::Type::MemberPointer:
3946
5
    return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3947
3948
27.8k
  case clang::Type::ObjCObjectPointer:
3949
27.8k
    if (pointee_or_element_clang_type)
3950
0
      pointee_or_element_clang_type->SetCompilerType(
3951
0
          this, qual_type->getPointeeType().getAsOpaquePtr());
3952
27.8k
    return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3953
27.8k
           eTypeHasValue;
3954
3955
0
  case clang::Type::ObjCObject:
3956
0
    return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3957
3.83k
  case clang::Type::ObjCInterface:
3958
3.83k
    return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3959
3960
117k
  case clang::Type::Pointer:
3961
117k
    if (pointee_or_element_clang_type)
3962
3.55k
      pointee_or_element_clang_type->SetCompilerType(
3963
3.55k
          this, qual_type->getPointeeType().getAsOpaquePtr());
3964
117k
    return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3965
3966
93.9k
  case clang::Type::Record:
3967
93.9k
    if (qual_type->getAsCXXRecordDecl())
3968
93.9k
      return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3969
0
    else
3970
0
      return eTypeHasChildren | eTypeIsStructUnion;
3971
0
    break;
3972
0
  case clang::Type::SubstTemplateTypeParm:
3973
0
    return eTypeIsTemplate;
3974
0
  case clang::Type::TemplateTypeParm:
3975
0
    return eTypeIsTemplate;
3976
0
  case clang::Type::TemplateSpecialization:
3977
0
    return eTypeIsTemplate;
3978
3979
146k
  case clang::Type::Typedef:
3980
146k
    return eTypeIsTypedef | GetType(llvm::cast<clang::TypedefType>(qual_type)
3981
146k
                                        ->getDecl()
3982
146k
                                        ->getUnderlyingType())
3983
146k
                                .GetTypeInfo(pointee_or_element_clang_type);
3984
0
  case clang::Type::UnresolvedUsing:
3985
0
    return 0;
3986
3987
1.17k
  case clang::Type::ExtVector:
3988
1.17k
  case clang::Type::Vector: {
3989
1.17k
    uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
3990
1.17k
    const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
3991
1.17k
        qual_type->getCanonicalTypeInternal());
3992
1.17k
    if (vector_type) {
3993
1.17k
      if (vector_type->isIntegerType())
3994
0
        vector_type_flags |= eTypeIsFloat;
3995
1.17k
      else if (vector_type->isFloatingType())
3996
0
        vector_type_flags |= eTypeIsInteger;
3997
1.17k
    }
3998
1.17k
    return vector_type_flags;
3999
1.17k
  }
4000
0
  default:
4001
0
    return 0;
4002
636k
  }
4003
0
  return 0;
4004
636k
}
4005
4006
lldb::LanguageType
4007
815k
TypeSystemClang::GetMinimumLanguage(lldb::opaque_compiler_type_t type) {
4008
815k
  if (!type)
4009
23.5k
    return lldb::eLanguageTypeC;
4010
4011
  // If the type is a reference, then resolve it to what it refers to first:
4012
791k
  clang::QualType qual_type(GetCanonicalQualType(type).getNonReferenceType());
4013
791k
  if (qual_type->isAnyPointerType()) {
4014
230k
    if (qual_type->isObjCObjectPointerType())
4015
42.0k
      return lldb::eLanguageTypeObjC;
4016
188k
    if (qual_type->getPointeeCXXRecordDecl())
4017
150k
      return lldb::eLanguageTypeC_plus_plus;
4018
4019
38.2k
    clang::QualType pointee_type(qual_type->getPointeeType());
4020
38.2k
    if (pointee_type->getPointeeCXXRecordDecl())
4021
951
      return lldb::eLanguageTypeC_plus_plus;
4022
37.3k
    if (pointee_type->isObjCObjectOrInterfaceType())
4023
0
      return lldb::eLanguageTypeObjC;
4024
37.3k
    if (pointee_type->isObjCClassType())
4025
0
      return lldb::eLanguageTypeObjC;
4026
37.3k
    if (pointee_type.getTypePtr() ==
4027
37.3k
        getASTContext().ObjCBuiltinIdTy.getTypePtr())
4028
168
      return lldb::eLanguageTypeObjC;
4029
560k
  } else {
4030
560k
    if (qual_type->isObjCObjectOrInterfaceType())
4031
7.38k
      return lldb::eLanguageTypeObjC;
4032
553k
    if (qual_type->getAsCXXRecordDecl())
4033
251k
      return lldb::eLanguageTypeC_plus_plus;
4034
301k
    switch (qual_type->getTypeClass()) {
4035
33.7k
    default:
4036
33.7k
      break;
4037
268k
    case clang::Type::Builtin:
4038
268k
      switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4039
238
      default:
4040
238
      case clang::BuiltinType::Void:
4041
76.5k
      case clang::BuiltinType::Bool:
4042
76.6k
      case clang::BuiltinType::Char_U:
4043
82.1k
      case clang::BuiltinType::UChar:
4044
82.1k
      case clang::BuiltinType::WChar_U:
4045
82.2k
      case clang::BuiltinType::Char16:
4046
82.3k
      case clang::BuiltinType::Char32:
4047
90.3k
      case clang::BuiltinType::UShort:
4048
101k
      case clang::BuiltinType::UInt:
4049
110k
      case clang::BuiltinType::ULong:
4050
114k
      case clang::BuiltinType::ULongLong:
4051
114k
      case clang::BuiltinType::UInt128:
4052
121k
      case clang::BuiltinType::Char_S:
4053
122k
      case clang::BuiltinType::SChar:
4054
122k
      case clang::BuiltinType::WChar_S:
4055
126k
      case clang::BuiltinType::Short:
4056
243k
      case clang::BuiltinType::Int:
4057
248k
      case clang::BuiltinType::Long:
4058
251k
      case clang::BuiltinType::LongLong:
4059
251k
      case clang::BuiltinType::Int128:
4060
260k
      case clang::BuiltinType::Float:
4061
266k
      case clang::BuiltinType::Double:
4062
266k
      case clang::BuiltinType::LongDouble:
4063
266k
        break;
4064
4065
0
      case clang::BuiltinType::NullPtr:
4066
0
        return eLanguageTypeC_plus_plus;
4067
4068
1.36k
      case clang::BuiltinType::ObjCId:
4069
1.65k
      case clang::BuiltinType::ObjCClass:
4070
1.67k
      case clang::BuiltinType::ObjCSel:
4071
1.67k
        return eLanguageTypeObjC;
4072
4073
0
      case clang::BuiltinType::Dependent:
4074
0
      case clang::BuiltinType::Overload:
4075
0
      case clang::BuiltinType::BoundMember:
4076
0
      case clang::BuiltinType::UnknownAny:
4077
0
        break;
4078
268k
      }
4079
266k
      break;
4080
266k
    case clang::Type::Typedef:
4081
0
      return GetType(llvm::cast<clang::TypedefType>(qual_type)
4082
0
                         ->getDecl()
4083
0
                         ->getUnderlyingType())
4084
0
          .GetMinimumLanguage();
4085
301k
    }
4086
301k
  }
4087
337k
  return lldb::eLanguageTypeC;
4088
791k
}
4089
4090
lldb::TypeClass
4091
22
TypeSystemClang::GetTypeClass(lldb::opaque_compiler_type_t type) {
4092
22
  if (!type)
4093
0
    return lldb::eTypeClassInvalid;
4094
4095
22
  clang::QualType qual_type =
4096
22
      RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef});
4097
4098
22
  switch (qual_type->getTypeClass()) {
4099
0
  case clang::Type::Atomic:
4100
0
  case clang::Type::Auto:
4101
0
  case clang::Type::Decltype:
4102
0
  case clang::Type::Elaborated:
4103
0
  case clang::Type::Paren:
4104
0
  case clang::Type::TypeOf:
4105
0
  case clang::Type::TypeOfExpr:
4106
0
  case clang::Type::Using:
4107
0
    llvm_unreachable("Handled in RemoveWrappingTypes!");
4108
0
  case clang::Type::UnaryTransform:
4109
0
    break;
4110
0
  case clang::Type::FunctionNoProto:
4111
0
    return lldb::eTypeClassFunction;
4112
0
  case clang::Type::FunctionProto:
4113
0
    return lldb::eTypeClassFunction;
4114
0
  case clang::Type::IncompleteArray:
4115
0
    return lldb::eTypeClassArray;
4116
0
  case clang::Type::VariableArray:
4117
0
    return lldb::eTypeClassArray;
4118
0
  case clang::Type::ConstantArray:
4119
0
    return lldb::eTypeClassArray;
4120
0
  case clang::Type::DependentSizedArray:
4121
0
    return lldb::eTypeClassArray;
4122
0
  case clang::Type::DependentSizedExtVector:
4123
0
    return lldb::eTypeClassVector;
4124
0
  case clang::Type::DependentVector:
4125
0
    return lldb::eTypeClassVector;
4126
0
  case clang::Type::ExtVector:
4127
0
    return lldb::eTypeClassVector;
4128
0
  case clang::Type::Vector:
4129
0
    return lldb::eTypeClassVector;
4130
4
  case clang::Type::Builtin:
4131
  // Ext-Int is just an integer type.
4132
4
  case clang::Type::BitInt:
4133
4
  case clang::Type::DependentBitInt:
4134
4
    return lldb::eTypeClassBuiltin;
4135
3
  case clang::Type::ObjCObjectPointer:
4136
3
    return lldb::eTypeClassObjCObjectPointer;
4137
0
  case clang::Type::BlockPointer:
4138
0
    return lldb::eTypeClassBlockPointer;
4139
4
  case clang::Type::Pointer:
4140
4
    return lldb::eTypeClassPointer;
4141
0
  case clang::Type::LValueReference:
4142
0
    return lldb::eTypeClassReference;
4143
0
  case clang::Type::RValueReference:
4144
0
    return lldb::eTypeClassReference;
4145
0
  case clang::Type::MemberPointer:
4146
0
    return lldb::eTypeClassMemberPointer;
4147
0
  case clang::Type::Complex:
4148
0
    if (qual_type->isComplexType())
4149
0
      return lldb::eTypeClassComplexFloat;
4150
0
    else
4151
0
      return lldb::eTypeClassComplexInteger;
4152
0
  case clang::Type::ObjCObject:
4153
0
    return lldb::eTypeClassObjCObject;
4154
0
  case clang::Type::ObjCInterface:
4155
0
    return lldb::eTypeClassObjCInterface;
4156
10
  case clang::Type::Record: {
4157
10
    const clang::RecordType *record_type =
4158
10
        llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4159
10
    const clang::RecordDecl *record_decl = record_type->getDecl();
4160
10
    if (record_decl->isUnion())
4161
1
      return lldb::eTypeClassUnion;
4162
9
    else if (record_decl->isStruct())
4163
5
      return lldb::eTypeClassStruct;
4164
4
    else
4165
4
      return lldb::eTypeClassClass;
4166
10
  } 
break0
;
4167
0
  case clang::Type::Enum:
4168
0
    return lldb::eTypeClassEnumeration;
4169
1
  case clang::Type::Typedef:
4170
1
    return lldb::eTypeClassTypedef;
4171
0
  case clang::Type::UnresolvedUsing:
4172
0
    break;
4173
4174
0
  case clang::Type::Attributed:
4175
0
    break;
4176
0
  case clang::Type::TemplateTypeParm:
4177
0
    break;
4178
0
  case clang::Type::SubstTemplateTypeParm:
4179
0
    break;
4180
0
  case clang::Type::SubstTemplateTypeParmPack:
4181
0
    break;
4182
0
  case clang::Type::InjectedClassName:
4183
0
    break;
4184
0
  case clang::Type::DependentName:
4185
0
    break;
4186
0
  case clang::Type::DependentTemplateSpecialization:
4187
0
    break;
4188
0
  case clang::Type::PackExpansion:
4189
0
    break;
4190
4191
0
  case clang::Type::TemplateSpecialization:
4192
0
    break;
4193
0
  case clang::Type::DeducedTemplateSpecialization:
4194
0
    break;
4195
0
  case clang::Type::Pipe:
4196
0
    break;
4197
4198
  // pointer type decayed from an array or function type.
4199
0
  case clang::Type::Decayed:
4200
0
    break;
4201
0
  case clang::Type::Adjusted:
4202
0
    break;
4203
0
  case clang::Type::ObjCTypeParam:
4204
0
    break;
4205
4206
0
  case clang::Type::DependentAddressSpace:
4207
0
    break;
4208
0
  case clang::Type::MacroQualified:
4209
0
    break;
4210
4211
  // Matrix types that we're not sure how to display at the moment.
4212
0
  case clang::Type::ConstantMatrix:
4213
0
  case clang::Type::DependentSizedMatrix:
4214
0
    break;
4215
22
  }
4216
  // We don't know hot to display this type...
4217
0
  return lldb::eTypeClassOther;
4218
22
}
4219
4220
0
unsigned TypeSystemClang::GetTypeQualifiers(lldb::opaque_compiler_type_t type) {
4221
0
  if (type)
4222
0
    return GetQualType(type).getQualifiers().getCVRQualifiers();
4223
0
  return 0;
4224
0
}
4225
4226
// Creating related types
4227
4228
CompilerType
4229
TypeSystemClang::GetArrayElementType(lldb::opaque_compiler_type_t type,
4230
1.04k
                                     ExecutionContextScope *exe_scope) {
4231
1.04k
  if (type) {
4232
1.04k
    clang::QualType qual_type(GetQualType(type));
4233
4234
1.04k
    const clang::Type *array_eletype =
4235
1.04k
        qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4236
4237
1.04k
    if (!array_eletype)
4238
0
      return CompilerType();
4239
4240
1.04k
    return GetType(clang::QualType(array_eletype, 0));
4241
1.04k
  }
4242
0
  return CompilerType();
4243
1.04k
}
4244
4245
CompilerType TypeSystemClang::GetArrayType(lldb::opaque_compiler_type_t type,
4246
147
                                           uint64_t size) {
4247
147
  if (type) {
4248
147
    clang::QualType qual_type(GetCanonicalQualType(type));
4249
147
    clang::ASTContext &ast_ctx = getASTContext();
4250
147
    if (size != 0)
4251
147
      return GetType(ast_ctx.getConstantArrayType(
4252
147
          qual_type, llvm::APInt(64, size), nullptr,
4253
147
          clang::ArrayType::ArraySizeModifier::Normal, 0));
4254
0
    else
4255
0
      return GetType(ast_ctx.getIncompleteArrayType(
4256
0
          qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0));
4257
147
  }
4258
4259
0
  return CompilerType();
4260
147
}
4261
4262
CompilerType
4263
75
TypeSystemClang::GetCanonicalType(lldb::opaque_compiler_type_t type) {
4264
75
  if (type)
4265
75
    return GetType(GetCanonicalQualType(type));
4266
0
  return CompilerType();
4267
75
}
4268
4269
static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast,
4270
25.3k
                                                    clang::QualType qual_type) {
4271
25.3k
  if (qual_type->isPointerType())
4272
4.34k
    qual_type = ast->getPointerType(
4273
4.34k
        GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
4274
21.0k
  else if (const ConstantArrayType *arr =
4275
21.0k
               ast->getAsConstantArrayType(qual_type)) {
4276
772
    qual_type = ast->getConstantArrayType(
4277
772
        GetFullyUnqualifiedType_Impl(ast, arr->getElementType()),
4278
772
        arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4279
772
        arr->getIndexTypeQualifiers().getAsOpaqueValue());
4280
772
  } else
4281
20.2k
    qual_type = qual_type.getUnqualifiedType();
4282
25.3k
  qual_type.removeLocalConst();
4283
25.3k
  qual_type.removeLocalRestrict();
4284
25.3k
  qual_type.removeLocalVolatile();
4285
25.3k
  return qual_type;
4286
25.3k
}
4287
4288
CompilerType
4289
20.2k
TypeSystemClang::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
4290
20.2k
  if (type)
4291
20.2k
    return GetType(
4292
20.2k
        GetFullyUnqualifiedType_Impl(&getASTContext(), GetQualType(type)));
4293
0
  return CompilerType();
4294
20.2k
}
4295
4296
CompilerType
4297
0
TypeSystemClang::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) {
4298
0
  if (type)
4299
0
    return GetEnumerationIntegerType(GetType(GetCanonicalQualType(type)));
4300
0
  return CompilerType();
4301
0
}
4302
4303
int TypeSystemClang::GetFunctionArgumentCount(
4304
0
    lldb::opaque_compiler_type_t type) {
4305
0
  if (type) {
4306
0
    const clang::FunctionProtoType *func =
4307
0
        llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type));
4308
0
    if (func)
4309
0
      return func->getNumParams();
4310
0
  }
4311
0
  return -1;
4312
0
}
4313
4314
CompilerType TypeSystemClang::GetFunctionArgumentTypeAtIndex(
4315
0
    lldb::opaque_compiler_type_t type, size_t idx) {
4316
0
  if (type) {
4317
0
    const clang::FunctionProtoType *func =
4318
0
        llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type));
4319
0
    if (func) {
4320
0
      const uint32_t num_args = func->getNumParams();
4321
0
      if (idx < num_args)
4322
0
        return GetType(func->getParamType(idx));
4323
0
    }
4324
0
  }
4325
0
  return CompilerType();
4326
0
}
4327
4328
CompilerType
4329
172
TypeSystemClang::GetFunctionReturnType(lldb::opaque_compiler_type_t type) {
4330
172
  if (type) {
4331
172
    clang::QualType qual_type(GetQualType(type));
4332
172
    const clang::FunctionProtoType *func =
4333
172
        llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4334
172
    if (func)
4335
172
      return GetType(func->getReturnType());
4336
172
  }
4337
0
  return CompilerType();
4338
172
}
4339
4340
size_t
4341
9
TypeSystemClang::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) {
4342
9
  size_t num_functions = 0;
4343
9
  if (type) {
4344
9
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4345
9
    switch (qual_type->getTypeClass()) {
4346
6
    case clang::Type::Record:
4347
6
      if (GetCompleteQualType(&getASTContext(), qual_type)) {
4348
6
        const clang::RecordType *record_type =
4349
6
            llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4350
6
        const clang::RecordDecl *record_decl = record_type->getDecl();
4351
6
        assert(record_decl);
4352
0
        const clang::CXXRecordDecl *cxx_record_decl =
4353
6
            llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4354
6
        if (cxx_record_decl)
4355
6
          num_functions = std::distance(cxx_record_decl->method_begin(),
4356
6
                                        cxx_record_decl->method_end());
4357
6
      }
4358
0
      break;
4359
4360
3
    case clang::Type::ObjCObjectPointer: {
4361
3
      const clang::ObjCObjectPointerType *objc_class_type =
4362
3
          qual_type->getAs<clang::ObjCObjectPointerType>();
4363
3
      const clang::ObjCInterfaceType *objc_interface_type =
4364
3
          objc_class_type->getInterfaceType();
4365
3
      if (objc_interface_type &&
4366
3
          GetCompleteType(static_cast<lldb::opaque_compiler_type_t>(
4367
3
              const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) {
4368
3
        clang::ObjCInterfaceDecl *class_interface_decl =
4369
3
            objc_interface_type->getDecl();
4370
3
        if (class_interface_decl) {
4371
3
          num_functions = std::distance(class_interface_decl->meth_begin(),
4372
3
                                        class_interface_decl->meth_end());
4373
3
        }
4374
3
      }
4375
3
      break;
4376
0
    }
4377
4378
0
    case clang::Type::ObjCObject:
4379
0
    case clang::Type::ObjCInterface:
4380
0
      if (GetCompleteType(type)) {
4381
0
        const clang::ObjCObjectType *objc_class_type =
4382
0
            llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4383
0
        if (objc_class_type) {
4384
0
          clang::ObjCInterfaceDecl *class_interface_decl =
4385
0
              objc_class_type->getInterface();
4386
0
          if (class_interface_decl)
4387
0
            num_functions = std::distance(class_interface_decl->meth_begin(),
4388
0
                                          class_interface_decl->meth_end());
4389
0
        }
4390
0
      }
4391
0
      break;
4392
4393
0
    default:
4394
0
      break;
4395
9
    }
4396
9
  }
4397
9
  return num_functions;
4398
9
}
4399
4400
TypeMemberFunctionImpl
4401
TypeSystemClang::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
4402
66
                                          size_t idx) {
4403
66
  std::string name;
4404
66
  MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown);
4405
66
  CompilerType clang_type;
4406
66
  CompilerDecl clang_decl;
4407
66
  if (type) {
4408
66
    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4409
66
    switch (qual_type->getTypeClass()) {
4410
57
    case clang::Type::Record:
4411
57
      if (GetCompleteQualType(&getASTContext(), qual_type)) {
4412
57
        const clang::RecordType *record_type =
4413
57
            llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4414
57
        const clang::RecordDecl *record_decl = record_type->getDecl();
4415
57
        assert(record_decl);
4416
0
        const clang::CXXRecordDecl *cxx_record_decl =
4417
57
            llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4418
57
        if (cxx_record_decl) {
4419
57
          auto method_iter = cxx_record_decl->method_begin();
4420
57
          auto method_end = cxx_record_decl->method_end();
4421
57
          if (idx <
4422
57
              static_cast<size_t>(std::distance(method_iter, method_end))) {
4423
57
            std::advance(method_iter, idx);
4424
57
            clang::CXXMethodDecl *cxx_method_decl =
4425
57
                method_iter->getCanonicalDecl();
4426
57
            if (cxx_method_decl) {
4427
57
              name = cxx_method_decl->getDeclName().getAsString();
4428
57
              if (cxx_method_decl->isStatic())
4429
15
                kind = lldb::eMemberFunctionKindStaticMethod;
4430
42
              else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4431
0
                kind = lldb::eMemberFunctionKindConstructor;
4432
42
              else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4433
0
                kind = lldb::eMemberFunctionKindDestructor;
4434
42
              else
4435
42
                kind = lldb::eMemberFunctionKindInstanceMethod;
4436
57
              clang_type = GetType(cxx_method_decl->getType());
4437
57
              clang_decl = GetCompilerDecl(cxx_method_decl);
4438
57
            }
4439
57
          }
4440
57
        }
4441
57
      }
4442
0
      break;
4443
4444
9
    case clang::Type::ObjCObjectPointer: {
4445
9
      const clang::ObjCObjectPointerType *objc_class_type =
4446
9
          qual_type->getAs<clang::ObjCObjectPointerType>();
4447
9
      const clang::ObjCInterfaceType *objc_interface_type =
4448
9
          objc_class_type->getInterfaceType();
4449
9
      if (objc_interface_type &&
4450
9
          GetCompleteType(static_cast<lldb::opaque_compiler_type_t>(
4451
9
              const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) {
4452
9
        clang::ObjCInterfaceDecl *class_interface_decl =
4453
9
            objc_interface_type->getDecl();
4454
9
        if (class_interface_decl) {
4455
9
          auto method_iter = class_interface_decl->meth_begin();
4456
9
          auto method_end = class_interface_decl->meth_end();
4457
9
          if (idx <
4458
9
              static_cast<size_t>(std::distance(method_iter, method_end))) {
4459
9
            std::advance(method_iter, idx);
4460
9
            clang::ObjCMethodDecl *objc_method_decl =
4461
9
                method_iter->getCanonicalDecl();
4462
9
            if (objc_method_decl) {
4463
9
              clang_decl = GetCompilerDecl(objc_method_decl);
4464
9
              name = objc_method_decl->getSelector().getAsString();
4465
9
              if (objc_method_decl->isClassMethod())
4466
0
                kind = lldb::eMemberFunctionKindStaticMethod;
4467
9
              else
4468
9
                kind = lldb::eMemberFunctionKindInstanceMethod;
4469
9
            }
4470
9
          }
4471
9
        }
4472
9
      }
4473
9
      break;
4474
0
    }
4475
4476
0
    case clang::Type::ObjCObject:
4477
0
    case clang::Type::ObjCInterface:
4478
0
      if (GetCompleteType(type)) {
4479
0
        const clang::ObjCObjectType *objc_class_type =
4480
0
            llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4481
0
        if (objc_class_type) {
4482
0
          clang::ObjCInterfaceDecl *class_interface_decl =
4483
0
              objc_class_type->getInterface();
4484
0
          if (class_interface_decl) {
4485
0
            auto method_iter = class_interface_decl->meth_begin();
4486
0
            auto method_end = class_interface_decl->meth_end();
4487
0
            if (idx <
4488
0
                static_cast<size_t>(std::distance(method_iter, method_end))) {
4489
0
              std::advance(method_iter, idx);
4490
0
              clang::ObjCMethodDecl *objc_method_decl =
4491
0
                  method_iter->getCanonicalDecl();
4492
0
              if (objc_method_decl) {
4493
0
                clang_decl = GetCompilerDecl(objc_method_decl);
4494
0
                name = objc_method_decl->getSelector().getAsString();
4495
0
                if (objc_method_decl->isClassMethod())
4496
0
                  kind = lldb::eMemberFunctionKindStaticMethod;
4497
0
                else
4498
0
                  kind = lldb::eMemberFunctionKindInstanceMethod;
4499
0
              }
4500
0
            }
4501
0
          }
4502
0
        }
4503
0
      }
4504
0
      break;
4505
4506
0
    default:
4507
0
      break;
4508
66
    }
4509
66
  }
4510
4511
66
  if (kind == eMemberFunctionKindUnknown)
4512
0
    return TypeMemberFunctionImpl();
4513
66
  else
4514
66
    return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind);
4515
66
}
4516
4517
CompilerType
4518
640
TypeSystemClang::GetNonReferenceType(lldb::opaque_compiler_type_t type) {
4519
640
  if (type)
4520
640
    return GetType(GetQualType(type).getNonReferenceType());
4521
0
  return CompilerType();
4522
640
}
4523
4524
CompilerType
4525
53.0k
TypeSystemClang::GetPointeeType(lldb::opaque_compiler_type_t type) {
4526
53.0k
  if (type) {
4527
53.0k
    clang::QualType qual_type(GetQualType(type));
4528
53.0k
    return GetType(qual_type.getTypePtr()->getPointeeType());
4529
53.0k
  }
4530
0
  return CompilerType();
4531
53.0k
}
4532
4533
CompilerType
4534
29.3k
TypeSystemClang::GetPointerType(lldb::opaque_compiler_type_t type) {
4535
29.3k
  if (type) {
4536
29.3k
    clang::QualType qual_type(GetQualType(type));
4537
4538
29.3k
    switch (qual_type.getDesugaredType(getASTContext())->getTypeClass()) {
4539
0
    case clang::Type::ObjCObject:
4540
3.39k
    case clang::Type::ObjCInterface:
4541
3.39k
      return GetType(getASTContext().getObjCObjectPointerType(qual_type));
4542
4543
25.9k
    default:
4544
25.9k
      return GetType(getASTContext().getPointerType(qual_type));
4545
29.3k
    }
4546
29.3k
  }
4547
0
  return CompilerType();
4548
29.3k
}
4549
4550
CompilerType
4551
26.9k
TypeSystemClang::GetLValueReferenceType(lldb::opaque_compiler_type_t type) {
4552
26.9k
  if (type)
4553
26.9k
    return GetType(getASTContext().getLValueReferenceType(GetQualType(type)));
4554
0
  else
4555
0
    return CompilerType();
4556
26.9k
}
4557
4558
CompilerType
4559
1.90k
TypeSystemClang::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
4560
1.90k
  if (type)
4561
1.90k
    return GetType(getASTContext().getRValueReferenceType(GetQualType(type)));
4562
0
  else
4563
0
    return CompilerType();
4564
1.90k
}
4565
4566
2
CompilerType TypeSystemClang::GetAtomicType(lldb::opaque_compiler_type_t type) {
4567
2
  if (!type)
4568
0
    return CompilerType();
4569
2
  return GetType(getASTContext().getAtomicType(GetQualType(type)));
4570
2
}
4571
4572
CompilerType
4573
5.88k
TypeSystemClang::AddConstModifier(lldb::opaque_compiler_type_t type) {
4574
5.88k
  if (type) {
4575
5.88k
    clang::QualType result(GetQualType(type));
4576
5.88k
    result.addConst();
4577
5.88k
    return GetType(result);
4578
5.88k
  }
4579
0
  return CompilerType();
4580
5.88k
}
4581
4582
CompilerType
4583
33
TypeSystemClang::AddVolatileModifier(lldb::opaque_compiler_type_t type) {
4584
33
  if (type) {
4585
33
    clang::QualType result(GetQualType(type));
4586
33
    result.addVolatile();
4587
33
    return GetType(result);
4588
33
  }
4589
0
  return CompilerType();
4590
33
}
4591
4592
CompilerType
4593
1
TypeSystemClang::AddRestrictModifier(lldb::opaque_compiler_type_t type) {
4594
1
  if (type) {
4595
1
    clang::QualType result(GetQualType(type));
4596
1
    result.addRestrict();
4597
1
    return GetType(result);
4598
1
  }
4599
0
  return CompilerType();
4600
1
}
4601
4602
CompilerType TypeSystemClang::CreateTypedef(
4603
    lldb::opaque_compiler_type_t type, const char *typedef_name,
4604
15.1k
    const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) {
4605
15.1k
  if (type && typedef_name && typedef_name[0]) {
4606
15.1k
    clang::ASTContext &clang_ast = getASTContext();
4607
15.1k
    clang::QualType qual_type(GetQualType(type));
4608
4609
15.1k
    clang::DeclContext *decl_ctx =
4610
15.1k
        TypeSystemClang::DeclContextGetAsDeclContext(compiler_decl_ctx);
4611
15.1k
    if (!decl_ctx)
4612
0
      decl_ctx = getASTContext().getTranslationUnitDecl();
4613
4614
15.1k
    clang::TypedefDecl *decl =
4615
15.1k
        clang::TypedefDecl::CreateDeserialized(clang_ast, 0);
4616
15.1k
    decl->setDeclContext(decl_ctx);
4617
15.1k
    decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4618
15.1k
    decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4619
15.1k
    decl_ctx->addDecl(decl);
4620
15.1k
    SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule());
4621
4622
15.1k
    clang::TagDecl *tdecl = nullptr;
4623
15.1k
    if (!qual_type.isNull()) {
4624
15.1k
      if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4625
5.58k
        tdecl = rt->getDecl();
4626
15.1k
      if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4627
24
        tdecl = et->getDecl();
4628
15.1k
    }
4629
4630
    // Check whether this declaration is an anonymous struct, union, or enum,
4631
    // hidden behind a typedef. If so, we try to check whether we have a
4632
    // typedef tag to attach to the original record declaration
4633
15.1k
    if (tdecl && 
!tdecl->getIdentifier()5.60k
&&
!tdecl->getTypedefNameForAnonDecl()87
)
4634
87
      tdecl->setTypedefNameForAnonDecl(decl);
4635
4636
15.1k
    decl->setAccess(clang::AS_public); // TODO respect proper access specifier
4637
4638
    // Get a uniqued clang::QualType for the typedef decl type
4639
15.1k
    return GetType(clang_ast.getTypedefType(decl));
4640
15.1k
  }
4641
0
  return CompilerType();
4642
15.1k
}
4643
4644
CompilerType
4645
4.80k
TypeSystemClang::GetTypedefedType(lldb::opaque_compiler_type_t type) {
4646
4.80k
  if (type) {
4647
4.80k
    const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4648
4.80k
        RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef}));
4649
4.80k
    if (typedef_type)
4650
4.77k
      return GetType(typedef_type->getDecl()->getUnderlyingType());
4651
4.80k
  }
4652
30
  return CompilerType();
4653
4.80k
}
4654
4655
// Create related types using the current type's AST
4656
4657
1.12k
CompilerType TypeSystemClang::GetBasicTypeFromAST(lldb::BasicType basic_type) {
4658
1.12k
  return TypeSystemClang::GetBasicType(basic_type);
4659
1.12k
}
4660
// Exploring the type
4661
4662
const llvm::fltSemantics &
4663
1.96k
TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) {
4664
1.96k
  clang::ASTContext &ast = getASTContext();
4665
1.96k
  const size_t bit_size = byte_size * 8;
4666
1.96k
  if (bit_size == ast.getTypeSize(ast.FloatTy))
4667
1.03k
    return ast.getFloatTypeSemantics(ast.FloatTy);
4668
934
  else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4669
922
    return ast.getFloatTypeSemantics(ast.DoubleTy);
4670
12
  else if (bit_size == ast.getTypeSize(ast.LongDoubleTy))
4671
9
    return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4672
3
  else if (bit_size == ast.getTypeSize(ast.HalfTy))
4673
1
    return ast.getFloatTypeSemantics(ast.HalfTy);
4674
2
  return llvm::APFloatBase::Bogus();
4675
1.96k
}
4676
4677
Optional<uint64_t>
4678
TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type,
4679
559k
                            ExecutionContextScope *exe_scope) {
4680
559k
  if (GetCompleteType(type)) {
4681
559k
    clang::QualType qual_type(GetCanonicalQualType(type));
4682
559k
    const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4683
559k
    switch (type_class) {
4684
23.5k
    case clang::Type::Record:
4685
23.5k
      if (GetCompleteType(type))
4686
23.5k
        return getASTContext().getTypeSize(qual_type);
4687
0
      else
4688
0
        return None;
4689
0
      break;
4690
4691
177
    case clang::Type::ObjCInterface:
4692
177
    case clang::Type::ObjCObject: {
4693
177
      ExecutionContext exe_ctx(exe_scope);
4694
177
      Process *process = exe_ctx.GetProcessPtr();
4695
177
      if (process) {
4696
174
        ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
4697
174
        if (objc_runtime) {
4698
174
          uint64_t bit_size = 0;
4699
174
          if (objc_runtime->GetTypeBitSize(GetType(qual_type), bit_size))
4700
138
            return bit_size;
4701
174
        }
4702
174
      } else {
4703
3
        static bool g_printed = false;
4704
3
        if (!g_printed) {
4705
1
          StreamString s;
4706
1
          DumpTypeDescription(type, &s);
4707
4708
1
          llvm::outs() << "warning: trying to determine the size of type ";
4709
1
          llvm::outs() << s.GetString() << "\n";
4710
1
          llvm::outs() << "without a valid ExecutionContext. this is not "
4711
1
                          "reliable. please file a bug against LLDB.\n";
4712
1
          llvm::outs() << "backtrace:\n";
4713
1
          llvm::sys::PrintStackTrace(llvm::outs());
4714
1
          llvm::outs() << "\n";
4715
1
          g_printed = true;
4716
1
        }
4717
3
      }
4718
177
    }
4719
177
      
LLVM_FALLTHROUGH39
;39
4720
536k
    default:
4721
536k
      const uint32_t bit_size = getASTContext().getTypeSize(qual_type);
4722
536k
      if (bit_size == 0) {
4723
113
        if (qual_type->isIncompleteArrayType())
4724
8
          return getASTContext().getTypeSize(
4725
8
              qual_type->getArrayElementTypeNoTypeQual()
4726
8
                  ->getCanonicalTypeUnqualified());
4727
113
      }
4728
536k
      if (qual_type->isObjCObjectOrInterfaceType())
4729
39
        return bit_size +
4730
39
               getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy);
4731
      // Function types actually have a size of 0, that's not an error.
4732
536k
      if (qual_type->isFunctionProtoType())
4733
86
        return bit_size;
4734
535k
      if (bit_size)
4735
535k
        return bit_size;
4736
559k
    }
4737
559k
  }
4738
238
  return None;
4739
559k
}
4740
4741
llvm::Optional<size_t>
4742
TypeSystemClang::GetTypeBitAlign(lldb::opaque_compiler_type_t type,
4743
20.0k
                                 ExecutionContextScope *exe_scope) {
4744
20.0k
  if (GetCompleteType(type))
4745
20.0k
    return getASTContext().getTypeAlign(GetQualType(type));
4746
0
  return {};
4747
20.0k
}
4748
4749
lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
4750
56.1k
                                            uint64_t &count) {
4751
56.1k
  if (!type)
4752
0
    return lldb::eEncodingInvalid;
4753
4754
56.1k
  count = 1;
4755
56.1k
  clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4756
4757
56.1k
  switch (qual_type->getTypeClass()) {
4758
0
  case clang::Type::Atomic:
4759
0
  case clang::Type::Auto:
4760
0
  case clang::Type::Decltype:
4761
0
  case clang::Type::Elaborated:
4762
0
  case clang::Type::Paren:
4763
0
  case clang::Type::Typedef:
4764
0
  case clang::Type::TypeOf:
4765
0
  case clang::Type::TypeOfExpr:
4766
0
  case clang::Type::Using:
4767
0
    llvm_unreachable("Handled in RemoveWrappingTypes!");
4768
4769
0
  case clang::Type::UnaryTransform:
4770
0
    break;
4771
4772
0
  case clang::Type::FunctionNoProto:
4773
0
  case clang::Type::FunctionProto:
4774
0
    break;
4775
4776
0
  case clang::Type::IncompleteArray:
4777
0
  case clang::Type::VariableArray:
4778
0
    break;
4779
4780
0
  case clang::Type::ConstantArray:
4781
0
    break;
4782
4783
0
  case clang::Type::DependentVector:
4784
0
  case clang::Type::ExtVector:
4785
0
  case clang::Type::Vector:
4786
    // TODO: Set this to more than one???
4787
0
    break;
4788
4789
0
  case clang::Type::BitInt:
4790
0
  case clang::Type::DependentBitInt:
4791
0
    return qual_type->isUnsignedIntegerType() ? lldb::eEncodingUint
4792
0
                                              : lldb::eEncodingSint;
4793
4794
32.8k
  case clang::Type::Builtin:
4795
32.8k
    switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4796
0
    case clang::BuiltinType::Void:
4797
0
      break;
4798
4799
50
    case clang::BuiltinType::Char_S:
4800
122
    case clang::BuiltinType::SChar:
4801
122
    case clang::BuiltinType::WChar_S:
4802
123
    case clang::BuiltinType::Short:
4803
897
    case clang::BuiltinType::Int:
4804
1.10k
    case clang::BuiltinType::Long:
4805
1.10k
    case clang::BuiltinType::LongLong:
4806
1.10k
    case clang::BuiltinType::Int128:
4807
1.10k
      return lldb::eEncodingSint;
4808
4809
19.6k
    case clang::BuiltinType::Bool:
4810
19.6k
    case clang::BuiltinType::Char_U:
4811
20.4k
    case clang::BuiltinType::UChar:
4812
20.4k
    case clang::BuiltinType::WChar_U:
4813
20.4k
    case clang::BuiltinType::Char8:
4814
20.4k
    case clang::BuiltinType::Char16:
4815
20.4k
    case clang::BuiltinType::Char32:
4816
20.4k
    case clang::BuiltinType::UShort:
4817
20.7k
    case clang::BuiltinType::UInt:
4818
31.5k
    case clang::BuiltinType::ULong:
4819
31.6k
    case clang::BuiltinType::ULongLong:
4820
31.6k
    case clang::BuiltinType::UInt128:
4821
31.6k
      return lldb::eEncodingUint;
4822
4823
    // Fixed point types. Note that they are currently ignored.
4824
0
    case clang::BuiltinType::ShortAccum:
4825
0
    case clang::BuiltinType::Accum:
4826
0
    case clang::BuiltinType::LongAccum:
4827
0
    case clang::BuiltinType::UShortAccum:
4828
0
    case clang::BuiltinType::UAccum:
4829
0
    case clang::BuiltinType::ULongAccum:
4830
0
    case clang::BuiltinType::ShortFract:
4831
0
    case clang::BuiltinType::Fract:
4832
0
    case clang::BuiltinType::LongFract:
4833
0
    case clang::BuiltinType::UShortFract:
4834
0
    case clang::BuiltinType::UFract:
4835
0
    case clang::BuiltinType::ULongFract:
4836
0
    case clang::BuiltinType::SatShortAccum:
4837
0
    case clang::BuiltinType::SatAccum:
4838
0
    case clang::BuiltinType::SatLongAccum:
4839
0
    case clang::BuiltinType::SatUShortAccum:
4840
0
    case clang::BuiltinType::SatUAccum:
4841
0
    case clang::BuiltinType::SatULongAccum:
4842
0
    case clang::BuiltinType::SatShortFract:
4843
0
    case clang::BuiltinType::SatFract:
4844
0
    case clang::BuiltinType::SatLongFract:
4845
0
    case clang::BuiltinType::SatUShortFract:
4846
0
    case clang::BuiltinType::SatUFract:
4847
0
    case clang::BuiltinType::SatULongFract:
4848
0
      break;
4849
4850
0
    case clang::BuiltinType::Half:
4851
0
    case clang::BuiltinType::Float:
4852
0
    case clang::BuiltinType::Float16:
4853
0
    case clang::BuiltinType::Float128:
4854
48
    case clang::BuiltinType::Double:
4855
48
    case clang::BuiltinType::LongDouble:
4856
48
    case clang::BuiltinType::BFloat16:
4857
48
    case clang::BuiltinType::Ibm128:
4858
48
      return lldb::eEncodingIEEE754;
4859
4860
0
    case clang::BuiltinType::ObjCClass:
4861
51
    case clang::BuiltinType::ObjCId:
4862
54
    case clang::BuiltinType::ObjCSel:
4863
54
      return lldb::eEncodingUint;
4864
4865
0
    case clang::BuiltinType::NullPtr:
4866
0
      return lldb::eEncodingUint;
4867
4868
0
    case clang::BuiltinType::Kind::ARCUnbridgedCast:
4869
0
    case clang::BuiltinType::Kind::BoundMember:
4870
0
    case clang::BuiltinType::Kind::BuiltinFn:
4871
0
    case clang::BuiltinType::Kind::Dependent:
4872
0
    case clang::BuiltinType::Kind::OCLClkEvent:
4873
0
    case clang::BuiltinType::Kind::OCLEvent:
4874
0
    case clang::BuiltinType::Kind::OCLImage1dRO:
4875
0
    case clang::BuiltinType::Kind::OCLImage1dWO:
4876
0
    case clang::BuiltinType::Kind::OCLImage1dRW:
4877
0
    case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4878
0
    case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4879
0
    case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4880
0
    case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4881
0
    case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4882
0
    case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4883
0
    case clang::BuiltinType::Kind::OCLImage2dRO:
4884
0
    case clang::BuiltinType::Kind::OCLImage2dWO:
4885
0
    case clang::BuiltinType::Kind::OCLImage2dRW:
4886
0
    case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4887
0
    case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4888
0
    case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4889
0
    case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4890
0
    case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4891
0
    case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4892
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4893
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4894
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4895
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4896
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4897
0
    case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4898
0
    case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4899
0
    case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4900
0
    case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4901
0
    case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4902
0
    case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4903
0
    case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4904
0
    case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4905
0
    case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4906
0
    case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4907
0
    case clang::BuiltinType::Kind::OCLImage3dRO:
4908
0
    case clang::BuiltinType::Kind::OCLImage3dWO:
4909
0
    case clang::BuiltinType::Kind::OCLImage3dRW:
4910
0
    case clang::BuiltinType::Kind::OCLQueue:
4911
0
    case clang::BuiltinType::Kind::OCLReserveID:
4912
0
    case clang::BuiltinType::Kind::OCLSampler:
4913
0
    case clang::BuiltinType::Kind::OMPArraySection:
4914
0
    case clang::BuiltinType::Kind::OMPArrayShaping:
4915
0
    case clang::BuiltinType::Kind::OMPIterator:
4916
0
    case clang::BuiltinType::Kind::Overload:
4917
0
    case clang::BuiltinType::Kind::PseudoObject:
4918
0
    case clang::BuiltinType::Kind::UnknownAny:
4919
0
      break;
4920
4921
0
    case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4922
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4923
0
    case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4924
0
    case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4925
0
    case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4926
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4927
0
    case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4928
0
    case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4929
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleRefStreamout:
4930
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualRefStreamout:
4931
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleRefStreamin:
4932
0
    case clang::BuiltinType::OCLIntelSubgroupAVCImeDualRefStreamin:
4933
0
      break;
4934
4935
    // PowerPC -- Matrix Multiply Assist
4936
0
    case clang::BuiltinType::VectorPair:
4937
0
    case clang::BuiltinType::VectorQuad:
4938
0
      break;
4939
4940
    // ARM -- Scalable Vector Extension
4941
0
    case clang::BuiltinType::SveBool:
4942
0
    case clang::BuiltinType::SveInt8:
4943
0
    case clang::BuiltinType::SveInt8x2:
4944
0
    case clang::BuiltinType::SveInt8x3:
4945
0
    case clang::BuiltinType::SveInt8x4:
4946
0
    case clang::BuiltinType::SveInt16:
4947
0
    case clang::BuiltinType::SveInt16x2:
4948
0
    case clang::BuiltinType::SveInt16x3:
4949
0
    case clang::BuiltinType::SveInt16x4:
4950
0
    case clang::BuiltinType::SveInt32:
4951
0
    case clang::BuiltinType::SveInt32x2:
4952
0
    case clang::BuiltinType::SveInt32x3:
4953
0
    case clang::BuiltinType::SveInt32x4:
4954
0
    case clang::BuiltinType::SveInt64:
4955
0
    case clang::BuiltinType::SveInt64x2:
4956
0
    case clang::BuiltinType::SveInt64x3:
4957
0
    case clang::BuiltinType::SveInt64x4:
4958
0
    case clang::BuiltinType::SveUint8:
4959
0
    case clang::BuiltinType::SveUint8x2:
4960
0
    case clang::BuiltinType::SveUint8x3:
4961
0
    case clang::BuiltinType::SveUint8x4:
4962
0
    case clang::BuiltinType::SveUint16:
4963
0
    case clang::BuiltinType::SveUint16x2:
4964
0
    case clang::BuiltinType::SveUint16x3:
4965
0
    case clang::BuiltinType::SveUint16x4:
4966
0
    case clang::BuiltinType::SveUint32:
4967
0
    case clang::BuiltinType::SveUint32x2:
4968
0
    case clang::BuiltinType::SveUint32x3:
4969
0
    case clang::BuiltinType::SveUint32x4:
4970
0
    case clang::BuiltinType::SveUint64:
4971
0
    case clang::BuiltinType::SveUint64x2:
4972
0
    case clang::BuiltinType::SveUint64x3:
4973
0
    case clang::BuiltinType::SveUint64x4:
4974
0
    case clang::BuiltinType::SveFloat16:
4975
0
    case clang::BuiltinType::SveBFloat16:
4976
0
    case clang::BuiltinType::SveBFloat16x2:
4977
0
    case clang::BuiltinType::SveBFloat16x3:
4978
0
    case clang::BuiltinType::SveBFloat16x4:
4979
0
    case clang::BuiltinType::SveFloat16x2:
4980
0
    case clang::BuiltinType::SveFloat16x3:
4981
0
    case clang::BuiltinType::SveFloat16x4:
4982
0
    case clang::BuiltinType::SveFloat32:
4983
0
    case clang::BuiltinType::SveFloat32x2:
4984
0
    case clang::BuiltinType::SveFloat32x3:
4985
0
    case clang::BuiltinType::SveFloat32x4:
4986
0
    case clang::BuiltinType::SveFloat64:
4987
0
    case clang::BuiltinType::SveFloat64x2:
4988
0
    case clang::BuiltinType::SveFloat64x3:
4989
0
    case clang::BuiltinType::SveFloat64x4:
4990
0
      break;
4991
4992
    // RISC-V V builtin types.
4993
0
    case clang::BuiltinType::RvvInt8mf8:
4994
0
    case clang::BuiltinType::RvvInt8mf4:
4995
0
    case clang::BuiltinType::RvvInt8mf2:
4996
0
    case clang::BuiltinType::RvvInt8m1:
4997
0
    case clang::BuiltinType::RvvInt8m2:
4998
0
    case clang::BuiltinType::RvvInt8m4:
4999
0
    case clang::BuiltinType::RvvInt8m8:
5000
0
    case clang::BuiltinType::RvvUint8mf8:
5001
0
    case clang::BuiltinType::RvvUint8mf4:
5002
0
    case clang::BuiltinType::RvvUint8mf2:
5003
0
    case clang::BuiltinType::RvvUint8m1:
5004
0
    case clang::BuiltinType::RvvUint8m2:
5005
0
    case clang::BuiltinType::RvvUint8m4:
5006
0
    case clang::BuiltinType::RvvUint8m8:
5007
0
    case clang::BuiltinType::RvvInt16mf4:
5008
0
    case clang::BuiltinType::RvvInt16mf2:
5009
0
    case clang::BuiltinType::RvvInt16m1:
5010
0
    case clang::BuiltinType::RvvInt16m2:
5011
0
    case clang::BuiltinType::RvvInt16m4:
5012
0
    case clang::BuiltinType::RvvInt16m8:
5013
0
    case clang::BuiltinType::RvvUint16mf4:
5014
0
    case clang::BuiltinType::RvvUint16mf2:
5015
0
    case clang::BuiltinType::RvvUint16m1:
5016
0
    case clang::BuiltinType::RvvUint16m2:
5017
0
    case clang::BuiltinType::RvvUint16m4:
5018
0
    case clang::BuiltinType::RvvUint16m8:
5019
0
    case clang::BuiltinType::RvvInt32mf2:
5020
0
    case clang::BuiltinType::RvvInt32m1:
5021
0
    case clang::BuiltinType::RvvInt32m2:
5022
0
    case clang::BuiltinType::RvvInt32m4:
5023
0
    case clang::BuiltinType::RvvInt32m8:
5024
0
    case clang::BuiltinType::RvvUint32mf2:
5025
0
    case clang::BuiltinType::RvvUint32m1:
5026
0
    case clang::BuiltinType::RvvUint32m2:
5027
0
    case clang::BuiltinType::RvvUint32m4: