Coverage Report

Created: 2023-09-30 09:22

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