clang 24.0.0git
QualTypeMapper.cpp
Go to the documentation of this file.
1//==---- QualTypeMapper.cpp - Maps Clang QualType to LLVMABI Types ---------==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Maps Clang QualType instances to corresponding LLVM ABI type
11/// representations. This mapper translates high-level type information from the
12/// AST into low-level ABI-specific types that encode size, alignment, and
13/// layout details required for code generation and cross-language
14/// interoperability.
15///
16//===----------------------------------------------------------------------===//
17#include "QualTypeMapper.h"
19#include "clang/AST/ASTFwd.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/DeclCXX.h"
24#include "clang/AST/Type.h"
26#include "clang/Basic/LLVM.h"
28#include "llvm/ABI/Types.h"
29#include "llvm/Support/Alignment.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/TypeSize.h"
32#include <cstdint>
33
34namespace clang {
35namespace CodeGen {
36
37/// Main entry point for converting Clang QualType to LLVM ABI Type.
38/// This method performs type canonicalization, caching, and dispatches
39/// to specialized conversion methods based on the type kind.
40///
41/// \param QT The Clang QualType to convert
42/// \return Corresponding LLVM ABI Type representation
43const llvm::abi::Type *QualTypeMapper::convertType(QualType QT) {
44 // Canonicalize type and strip qualifiers
45 // This ensures consistent type representation across different contexts
46 //
47 // TODO: AttributedType is NeverCanonical, so aligned typedef attributes
48 // for instance, __attribute__((aligned(N))) are lost here. Capture the
49 // effective alignment from the original QT and thread it through
50 // convertTypeImpl.
52
53 // Results are cached since type conversion may be expensive.
54 auto It = TypeCache.find(QT);
55 if (It != TypeCache.end())
56 return It->second;
57
58 const llvm::abi::Type *Result = convertTypeImpl(QT);
59 assert(Result && "convertTypeImpl returned nullptr");
60 TypeCache[QT] = Result;
61 return Result;
62}
63
64/// Dispatches to specialized conversion methods based on the type kind.
65const llvm::abi::Type *QualTypeMapper::convertTypeImpl(QualType QT) {
66 switch (QT->getTypeClass()) {
67 // Non-canonical and dependent types should have been stripped by
68 // getCanonicalType() above or cannot appear during code generation.
69#define TYPE(Class, Base)
70#define ABSTRACT_TYPE(Class, Base)
71#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
72#define DEPENDENT_TYPE(Class, Base) case Type::Class:
73#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
74#include "clang/AST/TypeNodes.inc"
75 llvm::reportFatalInternalError(
76 "Non-canonical or dependent types should not reach ABI lowering");
77
78 case Type::Builtin:
79 return convertBuiltinType(cast<BuiltinType>(QT));
80 case Type::Pointer:
81 return createPointerTypeForPointee(cast<PointerType>(QT)->getPointeeType());
82 case Type::LValueReference:
83 case Type::RValueReference:
84 return createPointerTypeForPointee(
86 case Type::ConstantArray:
87 case Type::ArrayParameter:
88 case Type::IncompleteArray:
89 case Type::VariableArray:
90 return convertArrayType(cast<ArrayType>(QT));
91 case Type::Vector:
92 case Type::ExtVector:
93 return convertVectorType(cast<VectorType>(QT));
94 case Type::Record:
95 return convertRecordType(cast<RecordType>(QT));
96 case Type::Enum:
97 return convertEnumType(cast<EnumType>(QT));
98 case Type::Complex:
99 return convertComplexType(cast<ComplexType>(QT));
100 case Type::Atomic:
101 return convertType(cast<AtomicType>(QT)->getValueType());
102 case Type::BlockPointer:
103 case Type::Pipe:
104 return createPointerTypeForPointee(ASTCtx.VoidPtrTy);
105 case Type::ConstantMatrix: {
106 const auto *MT = cast<ConstantMatrixType>(QT);
107 return Builder.getArrayType(convertType(MT->getElementType()),
108 MT->getNumRows() * MT->getNumColumns(),
109 ASTCtx.getTypeSize(QT), /*IsMatrixType=*/true);
110 }
111 case Type::MemberPointer:
112 return convertMemberPointerType(cast<MemberPointerType>(QT));
113 case Type::BitInt: {
114 const auto *BIT = cast<BitIntType>(QT);
115 return Builder.getIntegerType(BIT->getNumBits(), getTypeAlign(QT),
116 /*Signed=*/BIT->isSigned(),
117 /*IsBitInt=*/true);
118 }
119 case Type::ObjCObject:
120 case Type::ObjCInterface:
121 case Type::ObjCObjectPointer:
122 // Objective-C objects are represented as pointers in the ABI.
123 return Builder.getPointerType(
125 llvm::Align(
128 case Type::OverflowBehavior:
130 case Type::Auto:
131 case Type::DeducedTemplateSpecialization:
132 case Type::FunctionProto:
133 case Type::FunctionNoProto:
134 case Type::HLSLAttributedResource:
135 case Type::HLSLInlineSpirv:
136 llvm::reportFatalInternalError("Type not supported in ABI lowering");
137 }
138 llvm_unreachable("unhandled type class in convertTypeImpl");
139}
140
141/// Converts C/C++ builtin types to LLVM ABI types.
142/// This handles all fundamental scalar types including integers, floats,
143/// and special types like void and bool.
144const llvm::abi::Type *
145QualTypeMapper::convertBuiltinType(const BuiltinType *BT) {
146 QualType QT(BT, 0);
147
148 switch (BT->getKind()) {
149 case BuiltinType::Void:
150 return Builder.getVoidType();
151
152 case BuiltinType::NullPtr:
153 return createPointerTypeForPointee(QT);
154
155 case BuiltinType::Bool:
156 return Builder.getIntegerType(1, getTypeAlign(QT), /*Signed=*/false,
157 /*IsBitInt=*/false);
158
159 case BuiltinType::Char_S:
160 case BuiltinType::Char_U:
161 case BuiltinType::SChar:
162 case BuiltinType::UChar:
163 case BuiltinType::WChar_S:
164 case BuiltinType::WChar_U:
165 case BuiltinType::Char8:
166 case BuiltinType::Char16:
167 case BuiltinType::Char32:
168 case BuiltinType::Short:
169 case BuiltinType::UShort:
170 case BuiltinType::Int:
171 case BuiltinType::UInt:
172 case BuiltinType::Long:
173 case BuiltinType::ULong:
174 case BuiltinType::LongLong:
175 case BuiltinType::ULongLong:
176 case BuiltinType::Int128:
177 case BuiltinType::UInt128:
178 return Builder.getIntegerType(ASTCtx.getTypeSize(QT), getTypeAlign(QT),
179 /*Signed=*/BT->isSignedInteger(),
180 /*IsBitInt=*/false);
181
182 case BuiltinType::Half:
183 case BuiltinType::Float16:
184 case BuiltinType::BFloat16:
185 case BuiltinType::Float:
186 case BuiltinType::Double:
187 case BuiltinType::LongDouble:
188 case BuiltinType::Float128:
189 return Builder.getFloatType(ASTCtx.getFloatTypeSemantics(QT),
190 getTypeAlign(QT));
191
192 // TODO: IBM 128-bit extended double
193 case BuiltinType::Ibm128:
194 llvm::reportFatalInternalError(
195 "IBM128 is not yet supported in the ABI lowering libary");
196
197 // TODO: Fixed-point types
198 case BuiltinType::ShortAccum:
199 case BuiltinType::Accum:
200 case BuiltinType::LongAccum:
201 case BuiltinType::UShortAccum:
202 case BuiltinType::UAccum:
203 case BuiltinType::ULongAccum:
204 case BuiltinType::ShortFract:
205 case BuiltinType::Fract:
206 case BuiltinType::LongFract:
207 case BuiltinType::UShortFract:
208 case BuiltinType::UFract:
209 case BuiltinType::ULongFract:
210 case BuiltinType::SatShortAccum:
211 case BuiltinType::SatAccum:
212 case BuiltinType::SatLongAccum:
213 case BuiltinType::SatUShortAccum:
214 case BuiltinType::SatUAccum:
215 case BuiltinType::SatULongAccum:
216 case BuiltinType::SatShortFract:
217 case BuiltinType::SatFract:
218 case BuiltinType::SatLongFract:
219 case BuiltinType::SatUShortFract:
220 case BuiltinType::SatUFract:
221 case BuiltinType::SatULongFract:
222 llvm::reportFatalInternalError(
223 "Fixed Point types not yet implemented in the ABI lowering library");
224
225 // OpenCL image types are represented as opaque pointers.
226#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
227 case BuiltinType::Id:
228#include "clang/Basic/OpenCLImageTypes.def"
229 // OpenCL extension types are represented as opaque pointers.
230#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) case BuiltinType::Id:
231#include "clang/Basic/OpenCLExtensionTypes.def"
232 case BuiltinType::OCLSampler:
233 case BuiltinType::OCLEvent:
234 case BuiltinType::OCLClkEvent:
235 case BuiltinType::OCLQueue:
236 case BuiltinType::OCLReserveID:
237 return createPointerTypeForPointee(QT);
238
239 // Objective-C builtin types are represented as opaque pointers.
240 case BuiltinType::ObjCId:
241 case BuiltinType::ObjCClass:
242 case BuiltinType::ObjCSel:
243 return createPointerTypeForPointee(QT);
244
245 // Target-specific vector/matrix types — not yet implemented.
246#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
247#include "clang/Basic/AArch64ACLETypes.def"
248 llvm::reportFatalInternalError(
249 "AArch64 SVE types not yet supported in ABI lowering library");
250#define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:
251#include "clang/Basic/PPCTypes.def"
252 llvm::reportFatalInternalError(
253 "PPC MMA types not yet supported in ABI lowering library");
254#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
255#include "clang/Basic/RISCVVTypes.def"
256 llvm::reportFatalInternalError(
257 "RISC-V vector types not yet supported in ABI lowering library");
258#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
259#include "clang/Basic/WebAssemblyReferenceTypes.def"
260 llvm::reportFatalInternalError("WebAssembly reference types not yet "
261 "supported in ABI lowering library");
262#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
263#include "clang/Basic/AMDGPUTypes.def"
264 llvm::reportFatalInternalError(
265 "AMDGPU types not yet supported in ABI lowering library");
266#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
267#include "clang/Basic/HLSLIntangibleTypes.def"
268 llvm::reportFatalInternalError(
269 "HLSL intangible types not yet Supported in ABI lowering library");
270#define SPIRV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
271#include "clang/Basic/SPIRVTypes.def"
272 llvm::reportFatalInternalError(
273 "SPIR-V types not yet supported in ABI lowering library");
274
275 // Placeholder types should never reach ABI lowering.
276#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
277#define BUILTIN_TYPE(Id, SingletonId)
278#include "clang/AST/BuiltinTypes.def"
279 llvm::reportFatalInternalError(
280 "Placeholder type should not reach ABI lowering");
281
282 case BuiltinType::Dependent:
283 llvm::reportFatalInternalError(
284 "Dependent builtin type should not reach ABI lowering");
285 }
286 llvm_unreachable("unhandled builtin type kind in convertBuiltinType");
287}
288
289/// Converts array types to LLVM ABI array representations.
290/// Handles different array kinds: constant arrays, incomplete arrays,
291/// and variable-length arrays.
292///
293/// \param AT The ArrayType to convert
294/// \return LLVM ABI ArrayType or PointerType
295const llvm::abi::Type *
296QualTypeMapper::convertArrayType(const clang::ArrayType *AT) {
297 const llvm::abi::Type *ElementType = convertType(AT->getElementType());
298 uint64_t Size = ASTCtx.getTypeSize(AT);
299
300 if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
301 auto NumElements = CAT->getZExtSize();
302 return Builder.getArrayType(ElementType, NumElements, Size);
303 }
305 return Builder.getArrayType(ElementType, 0, 0);
306 if (const auto *VAT = dyn_cast<VariableArrayType>(AT))
307 return createPointerTypeForPointee(VAT->getPointeeType());
308 llvm::reportFatalInternalError(
309 "unexpected array type in ABI lowering (dependent array types should be "
310 "resolved before reaching this point)");
311}
312
313const llvm::abi::Type *QualTypeMapper::convertVectorType(const VectorType *VT) {
314 const llvm::abi::Type *ElementType = convertType(VT->getElementType());
315 QualType VectorQualType(VT, 0);
316
317 unsigned NElems = VT->getNumElements();
318 llvm::ElementCount NumElements = llvm::ElementCount::getFixed(NElems);
319 llvm::Align VectorAlign = getTypeAlign(VectorQualType);
320
321 return Builder.getVectorType(ElementType, NumElements, VectorAlign);
322}
323
324/// Converts complex types to LLVM ABI complex representations.
325/// Complex types consist of two components of the element type
326/// (real and imaginary parts).
327///
328/// \param CT The ComplexType to convert
329/// \return LLVM ABI ComplexType with element type and alignment
330const llvm::abi::Type *
331QualTypeMapper::convertComplexType(const ComplexType *CT) {
332 const llvm::abi::Type *ElementType = convertType(CT->getElementType());
333 llvm::Align ComplexAlign = getTypeAlign(QualType(CT, 0));
334
335 return Builder.getComplexType(ElementType, ComplexAlign);
336}
337
338/// Converts member pointer types to LLVM ABI representations.
339/// Member pointers have different layouts depending on whether they
340/// point to functions or data members.
341///
342/// \param MPT The MemberPointerType to convert
343/// \return LLVM ABI MemberPointerType
344const llvm::abi::Type *
345QualTypeMapper::convertMemberPointerType(const clang::MemberPointerType *MPT) {
346 QualType QT(MPT, 0);
347 uint64_t Size = ASTCtx.getTypeSize(QT);
348 llvm::Align Align = getTypeAlign(QT);
349
350 bool IsFunctionPointer = MPT->isMemberFunctionPointerType();
351
352 return Builder.getMemberPointerType(IsFunctionPointer, Size, Align);
353}
354
355/// Converts record types (struct/class/union) to LLVM ABI representations.
356/// This is the main dispatch method that handles different record kinds
357/// and delegates to specialized converters.
358///
359/// \param RT The RecordType to convert
360/// \return LLVM ABI RecordType
361const llvm::abi::Type *QualTypeMapper::convertRecordType(const RecordType *RT) {
362 const RecordDecl *RD = RT->getDecl()->getDefinition();
363 if (!RD)
364 return Builder.getRecordType({}, llvm::TypeSize::getFixed(0),
365 llvm::Align(1));
366
367 if (RD->isUnion())
368 return convertUnionType(RD);
369
370 // Handle C++ classes with base classes
371 auto *CXXRd = dyn_cast<CXXRecordDecl>(RD);
372 if (CXXRd && (CXXRd->getNumBases() > 0 || CXXRd->getNumVBases() > 0))
373 return convertCXXRecordType(CXXRd);
374 return convertStructType(RD);
375}
376
377/// Converts C++ classes with inheritance to LLVM ABI struct representations.
378/// This method handles the complex layout of C++ objects including:
379/// - Virtual table pointers for polymorphic classes
380/// - Base class subobjects (both direct and virtual bases)
381/// - Member field layout with proper offsets
382///
383/// \param RD The C++ record declaration
384/// \return LLVM ABI RecordType representing the complete object layout
385const llvm::abi::RecordType *
386QualTypeMapper::convertCXXRecordType(const CXXRecordDecl *RD) {
387 const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD);
388 SmallVector<llvm::abi::FieldInfo, 16> Fields;
389 SmallVector<llvm::abi::FieldInfo, 8> BaseClasses;
390 SmallVector<llvm::abi::FieldInfo, 8> VirtualBaseClasses;
391
392 // Add vtable pointer for polymorphic classes
393 if (RD->isPolymorphic()) {
394 const llvm::abi::Type *VtablePointer =
395 createPointerTypeForPointee(ASTCtx.VoidPtrTy);
396 Fields.emplace_back(VtablePointer, 0);
397 }
398
399 for (const auto &Base : RD->bases()) {
400 if (Base.isVirtual())
401 continue;
402
403 const RecordType *BaseRT = Base.getType()->castAs<RecordType>();
404 const llvm::abi::Type *BaseType = convertType(Base.getType());
405 uint64_t BaseOffset =
406 Layout.getBaseClassOffset(BaseRT->getAsCXXRecordDecl()).getQuantity() *
407 8;
408
409 BaseClasses.emplace_back(BaseType, BaseOffset);
410 }
411
412 for (const auto &VBase : RD->vbases()) {
413 const RecordType *VBaseRT = VBase.getType()->castAs<RecordType>();
414 const llvm::abi::Type *VBaseType = convertType(VBase.getType());
415 uint64_t VBaseOffset =
416 Layout.getVBaseClassOffset(VBaseRT->getAsCXXRecordDecl())
417 .getQuantity() *
418 8;
419
420 VirtualBaseClasses.emplace_back(VBaseType, VBaseOffset);
421 }
422
423 computeFieldInfo(RD, Fields, Layout);
424
425 llvm::sort(Fields,
426 [](const llvm::abi::FieldInfo &A, const llvm::abi::FieldInfo &B) {
427 return A.OffsetInBits < B.OffsetInBits;
428 });
429
430 llvm::TypeSize Size =
431 llvm::TypeSize::getFixed(Layout.getSize().getQuantity() * 8);
432 llvm::Align Alignment = llvm::Align(Layout.getAlignment().getQuantity());
433
434 llvm::abi::RecordFlags RecFlags = llvm::abi::RecordFlags::IsCXXRecord;
435 if (RD->isPolymorphic())
436 RecFlags |= llvm::abi::RecordFlags::IsPolymorphic;
437 if (RD->canPassInRegisters())
438 RecFlags |= llvm::abi::RecordFlags::CanPassInRegisters;
439 if (RD->hasFlexibleArrayMember())
440 RecFlags |= llvm::abi::RecordFlags::HasFlexibleArrayMember;
441
442 return Builder.getRecordType(Fields, Size, Alignment,
443 llvm::abi::StructPacking::Default, BaseClasses,
444 VirtualBaseClasses, RecFlags);
445}
446
447/// Converts enumeration types to their underlying integer representations.
448/// This method handles various enum states and falls back to safe defaults
449/// when enum information is incomplete or invalid.
450///
451/// \param ET The EnumType to convert
452/// \return LLVM ABI IntegerType representing the enum's underlying type
453const llvm::abi::Type *
454QualTypeMapper::convertEnumType(const clang::EnumType *ET) {
455 const EnumDecl *ED = ET->getDecl();
456 QualType UnderlyingType = ED->getIntegerType();
457
458 if (UnderlyingType.isNull())
459 UnderlyingType = ASTCtx.IntTy;
460
461 return convertType(UnderlyingType);
462}
463
464/// Converts plain C structs and C++ classes without inheritance.
465/// This handles the simpler case where we only need to layout member fields
466/// without considering base classes or virtual functions.
467///
468/// \param RD The RecordDecl to convert
469/// \return LLVM ABI RecordType
470const llvm::abi::RecordType *
471QualTypeMapper::convertStructType(const clang::RecordDecl *RD) {
472 const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD);
473
474 bool IsCXXRecord = isa<CXXRecordDecl>(RD);
475 SmallVector<llvm::abi::FieldInfo, 16> Fields;
476 computeFieldInfo(RD, Fields, Layout);
477
478 llvm::TypeSize Size =
479 llvm::TypeSize::getFixed(Layout.getSize().getQuantity() * 8);
480 llvm::Align Alignment = llvm::Align(Layout.getAlignment().getQuantity());
481
482 llvm::abi::RecordFlags RecFlags = llvm::abi::RecordFlags::None;
483 if (IsCXXRecord)
484 RecFlags |= llvm::abi::RecordFlags::IsCXXRecord;
485 if (RD->canPassInRegisters())
486 RecFlags |= llvm::abi::RecordFlags::CanPassInRegisters;
487 if (RD->hasFlexibleArrayMember())
488 RecFlags |= llvm::abi::RecordFlags::HasFlexibleArrayMember;
489
490 return Builder.getRecordType(Fields, Size, Alignment,
491 llvm::abi::StructPacking::Default, {}, {},
492 RecFlags);
493}
494
495/// Converts C union types where all fields occupy the same memory location.
496/// The union size is determined by its largest member, and all fields
497/// start at offset 0.
498///
499/// \param RD The RecordDecl representing the union
500/// \return LLVM ABI UnionType
501const llvm::abi::RecordType *
502QualTypeMapper::convertUnionType(const clang::RecordDecl *RD) {
503 const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD);
504
505 SmallVector<llvm::abi::FieldInfo, 16> AllFields;
506 computeFieldInfo(RD, AllFields, Layout);
507
508 llvm::TypeSize Size =
509 llvm::TypeSize::getFixed(Layout.getSize().getQuantity() * 8);
510 llvm::Align Alignment = llvm::Align(Layout.getAlignment().getQuantity());
511
512 llvm::abi::RecordFlags RecFlags = llvm::abi::RecordFlags::None;
513 if (RD->hasAttr<TransparentUnionAttr>())
514 RecFlags |= llvm::abi::RecordFlags::IsTransparent;
515 if (RD->canPassInRegisters())
516 RecFlags |= llvm::abi::RecordFlags::CanPassInRegisters;
517 if (isa<CXXRecordDecl>(RD))
518 RecFlags |= llvm::abi::RecordFlags::IsCXXRecord;
519
520 return Builder.getUnionType(AllFields, Size, Alignment,
521 llvm::abi::StructPacking::Default, RecFlags);
522}
523
524llvm::Align QualTypeMapper::getTypeAlign(QualType QT) const {
525
526 return llvm::Align(ASTCtx.getTypeAlignInChars(QT).getQuantity());
527}
528
529const llvm::abi::Type *
530QualTypeMapper::createPointerTypeForPointee(QualType PointeeType) {
531 auto AddrSpace = PointeeType.getAddressSpace();
532 auto PointerSize = ASTCtx.getTargetInfo().getPointerWidth(AddrSpace);
533 llvm::Align Alignment =
534 llvm::Align(ASTCtx.getTargetInfo().getPointerAlign(AddrSpace));
535 // Function types without an explicit address space qualifier use the program
536 // address space, which may differ from the default data address space on
537 // targets like AMDGPU.
538 unsigned TargetAddrSpace =
539 PointeeType->isFunctionType() && !PointeeType.hasAddressSpace()
540 ? DL.getProgramAddressSpace()
541 : ASTCtx.getTargetInfo().getTargetAddressSpace(AddrSpace);
542 return Builder.getPointerType(PointerSize, llvm::Align(Alignment.value() / 8),
543 TargetAddrSpace);
544}
545
546/// Processes the fields of a record (struct/class/union) and populates
547/// the Fields vector with FieldInfo objects containing type, offset,
548/// and bitfield information.
549///
550/// \param RD The RecordDecl whose fields to process
551/// \param Fields Output vector to populate with field information
552/// \param Layout The AST record layout containing field offset information
553void QualTypeMapper::computeFieldInfo(
554 const RecordDecl *RD, SmallVectorImpl<llvm::abi::FieldInfo> &Fields,
555 const ASTRecordLayout &Layout) {
556 unsigned FieldIndex = 0;
557
558 for (const auto *FD : RD->fields()) {
559 const llvm::abi::Type *FieldType = convertType(FD->getType());
560 uint64_t OffsetInBits = Layout.getFieldOffset(FieldIndex);
561
562 bool IsBitField = FD->isBitField();
563 uint64_t BitFieldWidth = 0;
564 bool IsUnnamedBitField = false;
565
566 if (IsBitField) {
567 BitFieldWidth = FD->getBitWidthValue();
568 IsUnnamedBitField = FD->isUnnamedBitField();
569 }
570
571 Fields.emplace_back(FieldType, OffsetInBits, IsBitField, BitFieldWidth,
572 IsUnnamedBitField);
573 ++FieldIndex;
574 }
575}
576
577} // namespace CodeGen
578} // namespace clang
Defines the clang::ASTContext interface.
Forward declaration of all AST node types.
Provides definitions for the various language-specific address spaces.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Maps Clang QualType instances to corresponding LLVM ABI type representations.
static QualType getUnderlyingType(const SubRegion *R)
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
CanQualType VoidPtrTy
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:943
QualType getElementType() const
Definition TypeBase.h:3848
const llvm::abi::Type * convertType(clang::QualType QT)
Main entry point for converting Clang QualType to LLVM ABI Type.
bool hasAttr() const
Definition DeclBase.h:585
A (possibly-)qualified type.
Definition TypeBase.h:938
LangAS getAddressSpace() const
Return the address space of this type.
Definition TypeBase.h:8628
QualType getCanonicalType() const
Definition TypeBase.h:8554
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8596
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4596
bool hasFlexibleArrayMember() const
Definition Decl.h:4492
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition TargetInfo.h:496
unsigned getTargetAddressSpace(LangAS AS) const
uint64_t getPointerAlign(LangAS AddrSpace) const
Definition TargetInfo.h:500
bool isMemberFunctionPointerType() const
Definition TypeBase.h:8824
TypeClass getTypeClass() const
Definition TypeBase.h:2449
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Result
The result type of a method or function.
Definition TypeBase.h:906
U cast(CodeGen::Address addr)
Definition Address.h:327
unsigned long uint64_t