clang 24.0.0git
CIRGenClass.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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// This contains code dealing with C++ code generation of classes
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenCXXABI.h"
14#include "CIRGenFunction.h"
15#include "CIRGenValue.h"
16
17#include "clang/AST/ExprCXX.h"
19#include "clang/AST/Type.h"
24
25using namespace clang;
26using namespace clang::CIRGen;
27
28namespace {
29// TODO(cir): a lot of what we see under this namespace is a strong candidate
30// to be shared between LLVM and CIR codegen.
31
32/// RAII object to indicate that codegen is copying the value representation
33/// instead of the object representation. Useful when copying a struct or
34/// class which has uninitialized members and we're only performing
35/// lvalue-to-rvalue conversion on the object but not its members.
36class CopyingValueRepresentation {
37public:
38 explicit CopyingValueRepresentation(CIRGenFunction &cgf)
39 : cgf(cgf), oldSanOpts(cgf.sanOpts) {
40 cgf.sanOpts.set(SanitizerKind::Bool, false);
41 cgf.sanOpts.set(SanitizerKind::Enum, false);
42 }
43 ~CopyingValueRepresentation() { cgf.sanOpts = oldSanOpts; }
44
45private:
46 CIRGenFunction &cgf;
47 SanitizerSet oldSanOpts;
48};
49
50class FieldMemcpyizer {
51public:
52 FieldMemcpyizer(CIRGenFunction &cgf, const CXXRecordDecl *classDecl,
53 SourceLocation methodLoc, const VarDecl *srcRec)
54 : cgf(cgf), classDecl(classDecl), methodLoc(methodLoc), srcRec(srcRec),
55 recLayout(cgf.getContext().getASTRecordLayout(classDecl)),
56 firstField(nullptr), lastField(nullptr), firstFieldOffset(0),
57 lastFieldOffset(0), lastAddedFieldIndex(0) {}
58
59 bool isMemcpyableField(FieldDecl *f) const {
60 // Never memcpy fields when we are adding poised paddings.
61 if (cgf.getContext().getLangOpts().SanitizeAddressFieldPadding)
62 return false;
63 Qualifiers qual = f->getType().getQualifiers();
64 if (qual.hasVolatile() || qual.hasObjCLifetime())
65 return false;
68 return true;
69 }
70
71 void addMemcpyableField(FieldDecl *f) {
72 if (CodeGenUtils::isEmptyFieldForLayout(cgf.getContext(), f))
73 return;
74 if (f->isZeroSize(cgf.getContext()))
75 return;
76 if (!firstField)
77 addInitialField(f);
78 else
79 addNextField(f);
80 }
81
82 CharUnits getMemcpySize(uint64_t firstByteOffset) const {
83 ASTContext &astContext = cgf.getContext();
84 unsigned lastFieldSize =
85 lastField->isBitField()
86 ? lastField->getBitWidthValue()
87 : astContext.toBits(
88 astContext.getTypeInfoDataSizeInChars(lastField->getType())
89 .Width);
90 uint64_t memcpySizeBits = lastFieldOffset + lastFieldSize -
91 firstByteOffset + astContext.getCharWidth() - 1;
92 return astContext.toCharUnitsFromBits(memcpySizeBits);
93 }
94
95 void emitMemcpy() {
96 // Give the subclass a chance to bail out if it feels the memcpy isn't worth
97 // it (e.g. Hasn't aggregated enough data).
98 if (!firstField)
99 return;
100
101 uint64_t firstByteOffset;
102 if (firstField->isBitField()) {
103 const CIRGenRecordLayout &rl =
104 cgf.getTypes().getCIRGenRecordLayout(firstField->getParent());
105 const CIRGenBitFieldInfo &bfInfo = rl.getBitFieldInfo(firstField);
106 // firstFieldOffset is not appropriate for bitfields,
107 // we need to use the storage offset instead.
108 firstByteOffset = cgf.getContext().toBits(bfInfo.storageOffset);
109 } else {
110 firstByteOffset = firstFieldOffset;
111 }
112
113 CharUnits memcpySize = getMemcpySize(firstByteOffset);
114 CanQualType recordTy = cgf.getContext().getCanonicalTagType(classDecl);
115 Address thisPtr = cgf.loadCXXThisAddress();
116 LValue destLv = cgf.makeAddrLValue(thisPtr, recordTy);
117 LValue dest = cgf.emitLValueForFieldInitialization(destLv, firstField,
118 firstField->getName());
119 cir::LoadOp srcPtr = cgf.getBuilder().createLoad(
120 cgf.getLoc(methodLoc), cgf.getAddrOfLocalVar(srcRec));
121 LValue srcLv = cgf.makeNaturalAlignAddrLValue(srcPtr, recordTy);
122 LValue src = cgf.emitLValueForFieldInitialization(srcLv, firstField,
123 firstField->getName());
124
125 emitMemcpyIR(dest.isBitField() ? dest.getBitFieldAddress()
126 : dest.getAddress(),
127 src.isBitField() ? src.getBitFieldAddress() : src.getAddress(),
128 memcpySize);
129 reset();
130 }
131
132 void reset() { firstField = nullptr; }
133
134protected:
135 CIRGenFunction &cgf;
136 const CXXRecordDecl *classDecl;
137 SourceLocation methodLoc;
138
139private:
140 void emitMemcpyIR(Address destPtr, Address srcPtr, CharUnits size) {
141 mlir::Location loc = cgf.getLoc(methodLoc);
142 CIRGenBuilderTy &builder = cgf.getBuilder();
143 mlir::Value sizeOp =
144 builder.getConstInt(loc, cgf.sizeTy, size.getQuantity());
145 Address destCast = destPtr.withElementType(builder, cgf.voidTy);
146 Address srcCast = srcPtr.withElementType(builder, cgf.voidTy);
147 builder.createMemCpy(loc, destCast, srcCast, sizeOp);
149 }
150
151 void addInitialField(FieldDecl *f) {
152 firstField = f;
153 lastField = f;
154 firstFieldOffset = recLayout.getFieldOffset(f->getFieldIndex());
155 lastFieldOffset = firstFieldOffset;
156 lastAddedFieldIndex = f->getFieldIndex();
157 }
158
159 void addNextField(FieldDecl *f) {
160 // For the most part, the following invariant will hold:
161 // f->getFieldIndex() == lastAddedFieldIndex + 1
162 // The one exception is that Sema won't add a copy-initializer for an
163 // unnamed bitfield, which will show up here as a gap in the sequence.
164 assert(f->getFieldIndex() >= lastAddedFieldIndex + 1 &&
165 "Cannot aggregate fields out of order.");
166 lastAddedFieldIndex = f->getFieldIndex();
167
168 // The 'first' and 'last' fields are chosen by offset, rather than field
169 // index. This allows the code to support bitfields, as well as regular
170 // fields.
171 uint64_t fOffset = recLayout.getFieldOffset(f->getFieldIndex());
172 if (fOffset < firstFieldOffset) {
173 firstField = f;
174 firstFieldOffset = fOffset;
175 } else if (fOffset >= lastFieldOffset) {
176 lastField = f;
177 lastFieldOffset = fOffset;
178 }
179 }
180
181 const VarDecl *srcRec;
182 const ASTRecordLayout &recLayout;
183 FieldDecl *firstField;
184 FieldDecl *lastField;
185 uint64_t firstFieldOffset, lastFieldOffset;
186 unsigned lastAddedFieldIndex;
187};
188
189class AssignmentMemcpyizer : public FieldMemcpyizer {
190 // Returns the memcpyable field copied by the given statement, if one
191 // exists. Otherwise returns null.
192 FieldDecl *getMemcpyableField(Stmt *s) {
193 if (!assignmentsMemcpyable)
194 return nullptr;
195 if (auto *bo = dyn_cast<BinaryOperator>(s)) {
196 // Recognise trivial assignments.
197 if (bo->getOpcode() != BO_Assign)
198 return nullptr;
199 auto *me = dyn_cast<MemberExpr>(bo->getLHS());
200 if (!me)
201 return nullptr;
202 auto *field = dyn_cast<FieldDecl>(me->getMemberDecl());
203 if (!field || !isMemcpyableField(field))
204 return nullptr;
205 Stmt *rhs = bo->getRHS();
206 if (auto *ec = dyn_cast<ImplicitCastExpr>(rhs))
207 rhs = ec->getSubExpr();
208 if (!rhs)
209 return nullptr;
210 if (auto *me2 = dyn_cast<MemberExpr>(rhs)) {
211 if (me2->getMemberDecl() == field)
212 return field;
213 }
214 return nullptr;
215 } else if (isa<CXXMemberCallExpr>(s)) {
216 // We want to represent all calls explicitly for analysis purposes.
217 return nullptr;
218 } else if (auto *ce = dyn_cast<CallExpr>(s)) {
219 // TODO(cir): https://github.com/llvm/clangir/issues/1177: This can result
220 // in memcpys instead of calls to trivial member functions.
221 auto *fd = dyn_cast<FunctionDecl>(ce->getCalleeDecl());
222 if (!fd || fd->getBuiltinID() != Builtin::BI__builtin_memcpy)
223 return nullptr;
224 Expr *dstPtr = ce->getArg(0);
225 if (auto *dc = dyn_cast<ImplicitCastExpr>(dstPtr))
226 dstPtr = dc->getSubExpr();
227 auto *duo = dyn_cast<UnaryOperator>(dstPtr);
228 if (!duo || duo->getOpcode() != UO_AddrOf)
229 return nullptr;
230 auto *me = dyn_cast<MemberExpr>(duo->getSubExpr());
231 if (!me)
232 return nullptr;
233 auto *field = dyn_cast<FieldDecl>(me->getMemberDecl());
234 if (!field || !isMemcpyableField(field))
235 return nullptr;
236 Expr *srcPtr = ce->getArg(1);
237 if (auto *sc = dyn_cast<ImplicitCastExpr>(srcPtr))
238 srcPtr = sc->getSubExpr();
239 auto *suo = dyn_cast<UnaryOperator>(srcPtr);
240 if (!suo || suo->getOpcode() != UO_AddrOf)
241 return nullptr;
242 auto *me2 = dyn_cast<MemberExpr>(suo->getSubExpr());
243 if (!me2 || field != dyn_cast<FieldDecl>(me2->getMemberDecl()))
244 return nullptr;
245 return field;
246 }
247
248 return nullptr;
249 }
250
251 const bool assignmentsMemcpyable;
252 SmallVector<Stmt *, 16> aggregatedStmts;
253
254public:
255 AssignmentMemcpyizer(CIRGenFunction &cgf, const CXXMethodDecl *ad,
256 FunctionArgList &args)
257 : FieldMemcpyizer(cgf, ad->getParent(), ad->getLocation(),
258 args[args.size() - 1]),
259 assignmentsMemcpyable(cgf.getLangOpts().getGC() == LangOptions::NonGC) {
260 assert(args.size() == 2);
261 }
262
263 void emitAssignment(Stmt *s) {
264 FieldDecl *f = getMemcpyableField(s);
265 if (f) {
266 addMemcpyableField(f);
267 aggregatedStmts.push_back(s);
268 } else {
269 emitAggregatedStmts();
270 if (cgf.emitStmt(s, /*useCurrentScope=*/true).failed())
271 assert(cgf.cgm.getDiags().hasErrorOccurred());
272 }
273 }
274
275 void emitAggregatedStmts() {
276 if (aggregatedStmts.size() <= 1) {
277 if (!aggregatedStmts.empty()) {
278 CopyingValueRepresentation cvr(cgf);
279 if (cgf.emitStmt(aggregatedStmts[0], /*useCurrentScope=*/true).failed())
280 assert(cgf.cgm.getDiags().hasErrorOccurred());
281 }
282 reset();
283 }
284
286 emitMemcpy();
287 aggregatedStmts.clear();
288 }
289
290 void finish() { emitAggregatedStmts(); }
291};
292} // namespace
293
294/// Return the smallest possible amount of storage that might be allocated
295/// starting from the beginning of an object of a particular class.
296///
297/// This may be smaller than sizeof(RD) if RD has virtual base classes.
299 if (!rd->hasDefinition())
300 return CharUnits::One();
301
302 auto &layout = getASTContext().getASTRecordLayout(rd);
303
304 // If the class is final, then we know that the pointer points to an
305 // object of that type and can use the full alignment.
306 if (rd->isEffectivelyFinal())
307 return layout.getSize();
308
309 // Otherwise, we have to assume it could be a subclass.
310 return std::max(layout.getNonVirtualSize(), CharUnits::One());
311}
312
313/// Checks whether the given constructor is a valid subject for the
314/// complete-to-base constructor delegation optimization, i.e. emitting the
315/// complete constructor as a simple call to the base constructor.
317 const CXXConstructorDecl *ctor) {
318 // Currently we disable the optimization for classes with virtual bases
319 // because (1) the address of parameter variables need to be consistent across
320 // all initializers but (2) the delegate function call necessarily creates a
321 // second copy of the parameter variable.
322 //
323 // The limiting example (purely theoretical AFAIK):
324 // struct A { A(int &c) { c++; } };
325 // struct A : virtual A {
326 // B(int count) : A(count) { printf("%d\n", count); }
327 // };
328 // ...although even this example could in principle be emitted as a delegation
329 // since the address of the parameter doesn't escape.
330 if (ctor->getParent()->getNumVBases())
331 return false;
332
333 // We also disable the optimization for variadic functions because it's
334 // impossible to "re-pass" varargs.
335 if (ctor->getType()->castAs<FunctionProtoType>()->isVariadic())
336 return false;
337
338 // FIXME: Decide if we can do a delegation of a delegating constructor.
339 if (ctor->isDelegatingConstructor())
340 return false;
341
342 return true;
343}
344
346 CXXCtorInitializer *memberInit,
347 LValue &lhs) {
348 FieldDecl *field = memberInit->getAnyMember();
349 if (memberInit->isIndirectMemberInitializer()) {
350 // If we are initializing an anonymous union field, drill down to the field.
351 IndirectFieldDecl *indirectField = memberInit->getIndirectMember();
352 for (const auto *nd : indirectField->chain()) {
353 auto *fd = cast<clang::FieldDecl>(nd);
354 lhs = cgf.emitLValueForFieldInitialization(lhs, fd, fd->getName());
355 }
356 } else {
357 lhs = cgf.emitLValueForFieldInitialization(lhs, field, field->getName());
358 }
359}
360
362 const CXXRecordDecl *classDecl,
363 CXXCtorInitializer *memberInit,
364 const CXXConstructorDecl *constructor,
365 FunctionArgList &args) {
366 assert(memberInit->isAnyMemberInitializer() &&
367 "Must have member initializer!");
368 assert(memberInit->getInit() && "Must have initializer!");
369
371
372 // non-static data member initializers
373 FieldDecl *field = memberInit->getAnyMember();
374 QualType fieldType = field->getType();
375
376 mlir::Value thisPtr = cgf.loadCXXThis();
377 CanQualType recordTy = cgf.getContext().getCanonicalTagType(classDecl);
378
379 // If a base constructor is being emitted, create an LValue that has the
380 // non-virtual alignment.
381 LValue lhs = (cgf.curGD.getCtorType() == Ctor_Base)
382 ? cgf.makeNaturalAlignPointeeAddrLValue(thisPtr, recordTy)
383 : cgf.makeNaturalAlignAddrLValue(thisPtr, recordTy);
384
385 emitLValueForAnyFieldInitialization(cgf, memberInit, lhs);
386
387 // Special case: If we are in a copy or move constructor, and we are copying
388 // an array off PODs or classes with trivial copy constructors, ignore the AST
389 // and perform the copy we know is equivalent.
390 // FIXME: This is hacky at best... if we had a bit more explicit information
391 // in the AST, we could generalize it more easily.
392 const ConstantArrayType *array =
393 cgf.getContext().getAsConstantArrayType(fieldType);
394 if (array && constructor->isDefaulted() &&
395 constructor->isCopyOrMoveConstructor()) {
396 QualType baseElementTy = cgf.getContext().getBaseElementType(array);
397 // NOTE(cir): CodeGen allows record types to be memcpy'd if applicable,
398 // whereas ClangIR wants to represent all object construction explicitly.
399 if (!baseElementTy->isRecordType()) {
400 unsigned srcArgIndex =
401 cgf.cgm.getCXXABI().getSrcArgforCopyCtor(constructor, args);
402 cir::LoadOp srcPtr = cgf.getBuilder().createLoad(
403 cgf.getLoc(memberInit->getSourceLocation()),
404 cgf.getAddrOfLocalVar(args[srcArgIndex]));
405 LValue thisRhslv = cgf.makeNaturalAlignAddrLValue(srcPtr, recordTy);
406 LValue src = cgf.emitLValueForFieldInitialization(thisRhslv, field,
407 field->getName());
408
409 // Copy the aggregate.
410 cgf.emitAggregateCopy(lhs, src, fieldType,
411 cgf.getOverlapForFieldInit(field),
412 lhs.isVolatileQualified());
413 // Ensure that we destroy the objects if an exception is thrown later in
414 // the constructor.
415 assert(!cgf.needsEHCleanup(fieldType.isDestructedType()) &&
416 "Arrays of non-record types shouldn't need EH cleanup");
417 return;
418 }
419 }
420
421 cgf.emitInitializerForField(field, lhs, memberInit->getInit());
422}
423
424namespace {
425/// Call the destructor for a direct base class.
426struct CallBaseDtor final : EHScopeStack::Cleanup {
427 const CXXRecordDecl *baseClass;
428 bool baseIsVirtual;
429 CallBaseDtor(const CXXRecordDecl *base, bool baseIsVirtual)
430 : baseClass(base), baseIsVirtual(baseIsVirtual) {}
431
432 void emit(CIRGenFunction &cgf, Flags flags) override {
433 const CXXRecordDecl *derivedClass =
434 cast<CXXMethodDecl>(cgf.curFuncDecl)->getParent();
435
436 const CXXDestructorDecl *d = baseClass->getDestructor();
437 // We are already inside a destructor, so presumably the object being
438 // destroyed should have the expected type.
439 QualType thisTy = d->getFunctionObjectParameterType();
440 assert(cgf.currSrcLoc && "expected source location");
442 cgf.getLoc(*cgf.currSrcLoc), cgf.loadCXXThisAddress(), derivedClass,
443 baseClass, baseIsVirtual);
444 cgf.emitCXXDestructorCall(d, Dtor_Base, baseIsVirtual,
445 /*delegating=*/false, addr, thisTy);
446 }
447};
448
449/// If the delegating constructor's body throws after the delegated-to
450/// constructor completes, destroy the object (mirrors CGClass.cpp's
451/// CallDelegatingCtorDtor).
452struct CallDelegatingCtorDtor final : EHScopeStack::Cleanup {
453 const CXXDestructorDecl *dtor;
454 Address addr;
456
457 CallDelegatingCtorDtor(const CXXDestructorDecl *dtor, Address addr,
459 : dtor(dtor), addr(addr), type(type) {}
460
461 void emit(CIRGenFunction &cgf, Flags flags) override {
462 QualType thisTy = dtor->getFunctionObjectParameterType();
463 cgf.emitCXXDestructorCall(dtor, type, /*forVirtualBase=*/false,
464 /*delegating=*/true, addr, thisTy);
465 }
466};
467
468} // end anonymous namespace
469
470/// Gets the address of a direct base class within a complete object.
471/// This should only be used for (1) non-virtual bases or (2) virtual bases
472/// when the type is known to be complete (e.g. in complete destructors).
473///
474/// The object pointed to by 'thisAddr' is assumed to be non-null.
476 mlir::Location loc, Address thisAddr, const CXXRecordDecl *derived,
477 const CXXRecordDecl *base, bool baseIsVirtual) {
478 // 'thisAddr' must be a pointer (in some address space) to Derived.
479 assert(thisAddr.getElementType() == convertType(derived));
480
481 // Compute the offset of the virtual base.
482 CharUnits offset;
483 const ASTRecordLayout &layout = getContext().getASTRecordLayout(derived);
484 if (baseIsVirtual)
485 offset = layout.getVBaseClassOffset(base);
486 else
487 offset = layout.getBaseClassOffset(base);
488
489 return builder.createBaseClassAddr(loc, thisAddr, convertType(base),
490 offset.getQuantity(),
491 /*assumeNotNull=*/true);
492}
493
495 const CXXRecordDecl *classDecl,
496 CXXCtorInitializer *baseInit) {
497 assert(curFuncDecl && "loading 'this' without a func declaration?");
499
500 assert(baseInit->isBaseInitializer() && "Must have base initializer!");
501
502 Address thisPtr = loadCXXThisAddress();
503
504 const Type *baseType = baseInit->getBaseClass();
505 const auto *baseClassDecl = baseType->castAsCXXRecordDecl();
506
507 bool isBaseVirtual = baseInit->isBaseVirtual();
508
509 // If the initializer for the base (other than the constructor
510 // itself) accesses 'this' in any way, we need to initialize the
511 // vtables.
513 initializeVTablePointers(loc, classDecl);
514
515 // We can pretend to be a complete class because it only matters for
516 // virtual bases, and we only do virtual bases for complete ctors.
518 loc, thisPtr, classDecl, baseClassDecl, isBaseVirtual);
522 getOverlapForBaseInit(classDecl, baseClassDecl, isBaseVirtual));
523
524 emitAggExpr(baseInit->getInit(), aggSlot);
525
526 if (cgm.getLangOpts().Exceptions && !baseClassDecl->hasTrivialDestructor())
527 ehStack.pushCleanup<CallBaseDtor>(EHCleanup, baseClassDecl,
528 /*baseIsVirtual=*/isBaseVirtual);
529}
530
531/// This routine generates necessary code to initialize base classes and
532/// non-static data members belonging to this constructor.
534 CXXCtorType ctorType,
535 FunctionArgList &args) {
536 if (cd->isDelegatingConstructor()) {
538 return;
539 }
540
541 const CXXRecordDecl *classDecl = cd->getParent();
542
543 // Virtual base initializers aren't needed if:
544 // - This is a base ctor variant
545 // - There are no vbases
546 // - The class is abstract, so a complete object of it cannot be constructed
547 //
548 // The check for an abstract class is necessary because sema may not have
549 // marked virtual base destructors referenced.
550 bool constructVBases = ctorType != Ctor_Base &&
551 classDecl->getNumVBases() != 0 &&
552 !classDecl->isAbstract();
553 if (constructVBases &&
554 !cgm.getTarget().getCXXABI().hasConstructorVariants()) {
555 cgm.errorNYI(cd->getSourceRange(),
556 "emitCtorPrologue: virtual base without variants");
557 return;
558 }
559
560 // Create three separate ranges for the different types of initializers.
561 auto allInits = cd->inits();
562
563 // Find the boundaries between the three groups.
564 auto virtualBaseEnd = std::find_if(
565 allInits.begin(), allInits.end(), [](const CXXCtorInitializer *Init) {
566 return !(Init->isBaseInitializer() && Init->isBaseVirtual());
567 });
568
569 auto nonVirtualBaseEnd = std::find_if(virtualBaseEnd, allInits.end(),
570 [](const CXXCtorInitializer *Init) {
571 return !Init->isBaseInitializer();
572 });
573
574 // Create the three ranges.
575 auto virtualBaseInits = llvm::make_range(allInits.begin(), virtualBaseEnd);
576 auto nonVirtualBaseInits =
577 llvm::make_range(virtualBaseEnd, nonVirtualBaseEnd);
578 auto memberInits = llvm::make_range(nonVirtualBaseEnd, allInits.end());
579
580 const mlir::Value oldThisValue = cxxThisValue;
581
582 auto emitInitializer = [&](CXXCtorInitializer *baseInit) {
583 if (cgm.getCodeGenOpts().StrictVTablePointers &&
584 cgm.getCodeGenOpts().OptimizationLevel > 0 &&
586 // It's OK to continue after emitting the error here. The missing code
587 // just "launders" the 'this' pointer.
588 cgm.errorNYI(cd->getSourceRange(),
589 "emitCtorPrologue: strict vtable pointers for vbase");
590 }
591 emitBaseInitializer(getLoc(cd->getBeginLoc()), classDecl, baseInit);
592 };
593
594 // Process virtual base initializers.
595 for (CXXCtorInitializer *virtualBaseInit : virtualBaseInits) {
596 if (!constructVBases)
597 continue;
598 emitInitializer(virtualBaseInit);
599 }
600
602
603 // Then, non-virtual base initializers.
604 for (CXXCtorInitializer *nonVirtualBaseInit : nonVirtualBaseInits) {
605 assert(!nonVirtualBaseInit->isBaseVirtual());
606 emitInitializer(nonVirtualBaseInit);
607 }
608
609 cxxThisValue = oldThisValue;
610
612
613 // Finally, initialize class members.
615 // Classic codegen uses a special class to attempt to replace member
616 // initializers with memcpy. We could possibly defer that to the
617 // lowering or optimization phases to keep the memory accesses more
618 // explicit. For now, we don't insert memcpy at all.
620 for (CXXCtorInitializer *member : memberInits) {
621 assert(!member->isBaseInitializer());
622 assert(member->isAnyMemberInitializer() &&
623 "Delegating initializer on non-delegating constructor");
624 emitMemberInitializer(*this, cd->getParent(), member, cd, args);
625 }
626}
627
629 mlir::Location loc, CIRGenFunction &cgf, Address addr,
630 CharUnits nonVirtualOffset, mlir::Value virtualOffset,
631 const CXXRecordDecl *derivedClass, const CXXRecordDecl *nearestVBase,
632 mlir::Type baseValueTy = {}, bool assumeNotNull = true) {
633 // Assert that we have something to do.
634 assert(!nonVirtualOffset.isZero() || virtualOffset != nullptr);
635
636 // Compute the offset from the static and dynamic components.
637 mlir::Value baseOffset;
638 if (!nonVirtualOffset.isZero()) {
639 if (virtualOffset) {
640 // The virtual offset is always a ptrdiff_t: how it is stored in the
641 // vtable is up to the lowering of cir.vtable.get_offset.
642 baseOffset = cgf.getBuilder().getConstInt(loc, cgf.ptrDiffTy,
643 nonVirtualOffset.getQuantity());
644 baseOffset = cgf.getBuilder().createAdd(loc, virtualOffset, baseOffset);
645 } else {
646 assert(baseValueTy && "expected base type");
647 // If no virtualOffset is present this is the final stop.
648 return cgf.getBuilder().createBaseClassAddr(
649 loc, addr, baseValueTy, nonVirtualOffset.getQuantity(),
650 assumeNotNull);
651 }
652 } else {
653 baseOffset = virtualOffset;
654 }
655
656 // Apply the base offset. cir.ptr_stride adjusts by a number of elements,
657 // not bytes. So the pointer must be cast to a byte pointer and back.
658
659 mlir::Value ptr = addr.getPointer();
660 mlir::Type charPtrType =
662 mlir::Value charPtr = cgf.getBuilder().createBitcast(ptr, charPtrType);
663 mlir::Value adjusted = cir::PtrStrideOp::create(
664 cgf.getBuilder(), loc, charPtrType, charPtr, baseOffset);
665 ptr = cgf.getBuilder().createBitcast(adjusted, ptr.getType());
666
667 // If we have a virtual component, the alignment of the result will
668 // be relative only to the known alignment of that vbase.
669 CharUnits alignment;
670 if (virtualOffset) {
671 assert(nearestVBase && "virtual offset without vbase?");
672 alignment = cgf.cgm.getVBaseAlignment(addr.getAlignment(), derivedClass,
673 nearestVBase);
674 } else {
675 alignment = addr.getAlignment();
676 }
677 alignment = alignment.alignmentAtOffset(nonVirtualOffset);
678
679 return Address(ptr, alignment);
680}
681
683 const VPtr &vptr) {
684 // Compute the address point.
685 mlir::Value vtableAddressPoint =
686 cgm.getCXXABI().getVTableAddressPointInStructor(
687 *this, vptr.vtableClass, vptr.base, vptr.nearestVBase);
688
689 if (!vtableAddressPoint)
690 return;
691
692 // Compute where to store the address point.
693 mlir::Value virtualOffset{};
694 CharUnits nonVirtualOffset = CharUnits::Zero();
695
696 mlir::Type baseValueTy;
697 if (cgm.getCXXABI().isVirtualOffsetNeededForVTableField(*this, vptr)) {
698 // We need to use the virtual base offset offset because the virtual base
699 // might have a different offset in the most derived class.
700 virtualOffset = cgm.getCXXABI().getVirtualBaseClassOffset(
701 loc, *this, loadCXXThisAddress(), vptr.vtableClass, vptr.nearestVBase);
702 nonVirtualOffset = vptr.offsetFromNearestVBase;
703 } else {
704 // We can just use the base offset in the complete class.
705 nonVirtualOffset = vptr.base.getBaseOffset();
706 baseValueTy =
707 convertType(getContext().getCanonicalTagType(vptr.base.getBase()));
708 }
709
710 // Apply the offsets.
711 Address classAddr = loadCXXThisAddress();
712 if (!nonVirtualOffset.isZero() || virtualOffset) {
714 loc, *this, classAddr, nonVirtualOffset, virtualOffset,
715 vptr.vtableClass, vptr.nearestVBase, baseValueTy);
716 }
717
718 // Finally, store the address point. Use the same CIR types as the field.
719 //
720 // vtable field is derived from `this` pointer, therefore they should be in
721 // the same addr space.
722 auto vtablePtr =
723 cir::VTableGetVPtrOp::create(builder, loc, classAddr.getPointer());
724 Address vtableField = Address(vtablePtr, classAddr.getAlignment());
725 builder.createStore(loc, vtableAddressPoint, vtableField);
728}
729
731 const CXXRecordDecl *rd) {
732 // Ignore classes without a vtable.
733 if (!rd->isDynamicClass())
734 return;
735
736 // Initialize the vtable pointers for this class and all of its bases.
737 if (cgm.getCXXABI().doStructorsInitializeVPtrs(rd))
738 for (const auto &vptr : getVTablePointers(rd))
739 initializeVTablePointer(loc, vptr);
740
741 if (rd->getNumVBases())
742 cgm.getCXXABI().initializeHiddenVirtualInheritanceMembers(*this, rd);
743}
744
747 CIRGenFunction::VPtrsVector vptrsResult;
750 /*NearestVBase=*/nullptr,
751 /*OffsetFromNearestVBase=*/CharUnits::Zero(),
752 /*BaseIsNonVirtualPrimaryBase=*/false, vtableClass, vbases,
753 vptrsResult);
754 return vptrsResult;
755}
756
758 const CXXRecordDecl *nearestVBase,
759 CharUnits offsetFromNearestVBase,
760 bool baseIsNonVirtualPrimaryBase,
761 const CXXRecordDecl *vtableClass,
763 VPtrsVector &vptrs) {
764 // If this base is a non-virtual primary base the address point has already
765 // been set.
766 if (!baseIsNonVirtualPrimaryBase) {
767 // Initialize the vtable pointer for this base.
768 VPtr vptr = {base, nearestVBase, offsetFromNearestVBase, vtableClass};
769 vptrs.push_back(vptr);
770 }
771
772 const CXXRecordDecl *rd = base.getBase();
773
774 for (const auto &nextBase : rd->bases()) {
775 const auto *baseDecl =
776 cast<CXXRecordDecl>(nextBase.getType()->castAs<RecordType>()->getDecl())
777 ->getDefinitionOrSelf();
778
779 // Ignore classes without a vtable.
780 if (!baseDecl->isDynamicClass())
781 continue;
782
783 CharUnits baseOffset;
784 CharUnits baseOffsetFromNearestVBase;
785 bool baseDeclIsNonVirtualPrimaryBase;
786 const CXXRecordDecl *nextBaseDecl;
787
788 if (nextBase.isVirtual()) {
789 // Check if we've visited this virtual base before.
790 if (!vbases.insert(baseDecl).second)
791 continue;
792
793 const ASTRecordLayout &layout =
794 getContext().getASTRecordLayout(vtableClass);
795
796 nextBaseDecl = baseDecl;
797 baseOffset = layout.getVBaseClassOffset(baseDecl);
798 baseOffsetFromNearestVBase = CharUnits::Zero();
799 baseDeclIsNonVirtualPrimaryBase = false;
800 } else {
801 const ASTRecordLayout &layout = getContext().getASTRecordLayout(rd);
802
803 nextBaseDecl = nearestVBase;
804 baseOffset = base.getBaseOffset() + layout.getBaseClassOffset(baseDecl);
805 baseOffsetFromNearestVBase =
806 offsetFromNearestVBase + layout.getBaseClassOffset(baseDecl);
807 baseDeclIsNonVirtualPrimaryBase = layout.getPrimaryBase() == baseDecl;
808 }
809
810 getVTablePointers(BaseSubobject(baseDecl, baseOffset), nextBaseDecl,
811 baseOffsetFromNearestVBase,
812 baseDeclIsNonVirtualPrimaryBase, vtableClass, vbases,
813 vptrs);
814 }
815}
816
818 assert(curFuncDecl && "loading 'this' without a func declaration?");
820
821 // Lazily compute CXXThisAlignment.
822 if (cxxThisAlignment.isZero()) {
823 // Just use the best known alignment for the parent.
824 // TODO: if we're currently emitting a complete-object ctor/dtor, we can
825 // always use the complete-object alignment.
826 auto rd = cast<CXXMethodDecl>(curFuncDecl)->getParent();
827 cxxThisAlignment = cgm.getClassPointerAlignment(rd);
828 }
829
831}
832
834 Expr *init) {
835 QualType fieldType = field->getType();
836 switch (getEvaluationKind(fieldType)) {
837 case cir::TEK_Scalar:
838 if (lhs.isSimple()) {
839 emitExprAsInit(init, field, lhs, false);
840 } else {
841 RValue rhs = RValue::get(emitScalarExpr(init));
842 emitStoreThroughLValue(rhs, lhs);
843 }
844 break;
845 case cir::TEK_Complex:
846 emitComplexExprIntoLValue(init, lhs, /*isInit=*/true);
847 break;
848 case cir::TEK_Aggregate: {
854 emitAggExpr(init, slot);
855 break;
856 }
857 }
858
859 // Ensure that we destroy this object if an exception is thrown later in the
860 // constructor.
861 QualType::DestructionKind dtorKind = fieldType.isDestructedType();
862 pushEHDestroyIfNeeded(dtorKind, lhs.getAddress(), fieldType);
863}
864
866 const Expr *e, Address base, mlir::Value memberPtr,
867 const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo) {
869
870 cir::GetRuntimeMemberOp op = builder.createGetIndirectMember(
871 getLoc(e->getSourceRange()), base.getPointer(), memberPtr);
872
873 QualType memberType = memberPtrType->getPointeeType();
875 CharUnits memberAlign = cgm.getNaturalTypeAlignment(memberType, baseInfo);
876 memberAlign = cgm.getDynamicOffsetAlignment(
877 base.getAlignment(), memberPtrType->getMostRecentCXXRecordDecl(),
878 memberAlign);
879
880 return Address(op, convertTypeForMem(memberPtrType->getPointeeType()),
881 memberAlign);
882}
883
886 const CXXRecordDecl *baseDecl,
887 CharUnits expectedTargetAlign) {
888 // If the base is an incomplete type (which is, alas, possible with
889 // member pointers), be pessimistic.
890 if (!baseDecl->isCompleteDefinition())
891 return std::min(actualBaseAlign, expectedTargetAlign);
892
893 const ASTRecordLayout &baseLayout =
895 CharUnits expectedBaseAlign = baseLayout.getNonVirtualAlignment();
896
897 // If the class is properly aligned, assume the target offset is, too.
898 //
899 // This actually isn't necessarily the right thing to do --- if the
900 // class is a complete object, but it's only properly aligned for a
901 // base subobject, then the alignments of things relative to it are
902 // probably off as well. (Note that this requires the alignment of
903 // the target to be greater than the NV alignment of the derived
904 // class.)
905 //
906 // However, our approach to this kind of under-alignment can only
907 // ever be best effort; after all, we're never going to propagate
908 // alignments through variables or parameters. Note, in particular,
909 // that constructing a polymorphic type in an address that's less
910 // than pointer-aligned will generally trap in the constructor,
911 // unless we someday add some sort of attribute to change the
912 // assumed alignment of 'this'. So our goal here is pretty much
913 // just to allow the user to explicitly say that a pointer is
914 // under-aligned and then safely access its fields and vtables.
915 if (actualBaseAlign >= expectedBaseAlign)
916 return expectedTargetAlign;
917
918 // Otherwise, we might be offset by an arbitrary multiple of the
919 // actual alignment. The correct adjustment is to take the min of
920 // the two alignments.
921 return std::min(actualBaseAlign, expectedTargetAlign);
922}
923
924/// Return the best known alignment for a pointer to a virtual base,
925/// given the alignment of a pointer to the derived class.
928 const CXXRecordDecl *derivedClass,
929 const CXXRecordDecl *vbaseClass) {
930 // The basic idea here is that an underaligned derived pointer might
931 // indicate an underaligned base pointer.
932
933 assert(vbaseClass->isCompleteDefinition());
934 const ASTRecordLayout &baseLayout =
935 getASTContext().getASTRecordLayout(vbaseClass);
936 CharUnits expectedVBaseAlign = baseLayout.getNonVirtualAlignment();
937
938 return getDynamicOffsetAlignment(actualDerivedAlign, derivedClass,
939 expectedVBaseAlign);
940}
941
942/// Emit a loop to call a particular constructor for each of several members
943/// of an array.
944///
945/// \param ctor the constructor to call for each element
946/// \param arrayType the type of the array to initialize
947/// \param arrayBegin an arrayType*
948/// \param zeroInitialize true if each element should be
949/// zero-initialized before it is constructed
952 Address arrayBegin, const CXXConstructExpr *e, bool newPointerIsChecked,
953 bool zeroInitialize) {
954 QualType elementType;
955 mlir::Value numElements = emitArrayLength(arrayType, elementType, arrayBegin);
956 emitCXXAggrConstructorCall(ctor, numElements, arrayBegin, e,
957 newPointerIsChecked, zeroInitialize,
958 /*endOfInit=*/Address::invalid());
959}
960
961/// Emit a loop to call a particular constructor for each of several members
962/// of an array.
963///
964/// \param ctor the constructor to call for each element
965/// \param numElements the number of elements in the array;
966/// may be zero
967/// \param arrayBase a T*, where T is the type constructed by ctor
968/// \param zeroInitialize true if each element should be
969/// zero-initialized before it is constructed
970/// \param endOfInit if valid, an alloca holding the upper bound of an
971/// already-pushed irregular partial-array EH cleanup. When valid, the
972/// loop body will update this slot before each constructor call so the
973/// caller's cleanup covers loop-constructed elements, and no
974/// partial-destruction region is attached to the resulting
975/// cir::ArrayCtor op.
977 const CXXConstructorDecl *ctor, mlir::Value numElements, Address arrayBase,
978 const CXXConstructExpr *e, bool newPointerIsChecked, bool zeroInitialize,
979 Address endOfInit) {
980 // It's legal for numElements to be zero. This can happen both
981 // dynamically, because x can be zero in 'new A[x]', and statically,
982 // because of GCC extensions that permit zero-length arrays. There
983 // are probably legitimate places where we could assume that this
984 // doesn't happen, but it's not clear that it's worth it.
985
986 // Peel any array types wrapped in the address element type down to the CIR
987 // type of a single constructed object.
988 mlir::Type elementType = arrayBase.getElementType();
989 while (auto maybeArrayTy = mlir::dyn_cast<cir::ArrayType>(elementType))
990 elementType = maybeArrayTy.getElementType();
991 cir::PointerType ptrToElmType =
992 builder.getPointerTo(elementType, arrayBase.getAddressSpace());
993
994 bool useDynamicArrayCtor = true;
995 uint64_t constElementCount = 0;
996 if (auto constantOp = numElements.getDefiningOp<cir::ConstantOp>()) {
997 constElementCount = CIRGenFunction::getZExtIntValueFromConstOp(constantOp);
998 if (constElementCount == 0)
999 return;
1000 if (constantOp.use_empty())
1001 constantOp.erase();
1002 useDynamicArrayCtor = false;
1003 }
1004
1005 // Traditional LLVM codegen emits a loop here. CIR lowers to a loop as part of
1006 // LoweringPrepare.
1007
1008 // The alignment of the base, adjusted by the size of a single element,
1009 // provides a conservative estimate of the alignment of every element.
1010 // (This assumes we never start tracking offsetted alignments.)
1011 //
1012 // Note that these are complete objects and so we don't need to
1013 // use the non-virtual size or alignment.
1015 CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement(
1016 getContext().getTypeSizeInChars(type));
1017
1018 mlir::Location loc = getLoc(*currSrcLoc);
1019
1020 mlir::Value dynamicElPtr;
1021 if (useDynamicArrayCtor)
1022 dynamicElPtr =
1023 builder.createPtrBitcast(arrayBase.getPointer(), elementType);
1024
1025 // When the caller has already pushed an irregular partial-array cleanup
1026 // (signalled by a valid endOfInit), our loop body will keep that cleanup's
1027 // upper bound up to date, so we don't need a separate per-element
1028 // partial-destruction region on the cir::ArrayCtor op.
1029 bool needsPartialArrayCleanup = getLangOpts().Exceptions &&
1030 !ctor->getParent()->hasTrivialDestructor() &&
1031 !endOfInit.isValid();
1032
1033 auto emitCtorBody = [&](mlir::OpBuilder &b, mlir::Location l) {
1034 mlir::BlockArgument arg =
1035 b.getInsertionBlock()->addArgument(ptrToElmType, l);
1036 Address curAddr = Address(arg, elementType, eltAlignment);
1037 // Extend the caller's irregular partial-array cleanup to cover the
1038 // element we're about to construct. If this constructor throws, the
1039 // cleanup will destroy every element strictly below this one.
1040 if (endOfInit.isValid())
1041 builder.createStore(l, arg, endOfInit);
1043 if (zeroInitialize)
1044 emitNullInitialization(l, curAddr, type);
1045 auto currAVS = AggValueSlot::forAddr(
1046 curAddr, type.getQualifiers(), AggValueSlot::IsDestructed,
1049 // C++ [class.temporary]p4:
1050 // There are two contexts in which temporaries are destroyed at a
1051 // different point than the end of the full-expression. The first context
1052 // is when a default constructor is called to initialize an element of an
1053 // array. If the constructor has one or more default arguments, the
1054 // destruction of every temporary created in a default argument expression
1055 // is sequenced before the construction of the next array element, if any.
1056 {
1057 FullExprCleanupScope scope(*this, e);
1060 /*ForVirtualBase=*/false,
1061 /*Delegating=*/false, currAVS, e);
1062 }
1063 cir::YieldOp::create(b, l);
1064 };
1065
1066 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>
1067 emitPartialDtorBody = nullptr;
1068 auto partialDtorBuilder = [&](mlir::OpBuilder &b, mlir::Location l) {
1069 mlir::BlockArgument arg =
1070 b.getInsertionBlock()->addArgument(ptrToElmType, l);
1071 Address curAddr = Address(arg, elementType, eltAlignment);
1073 /*forVirtualBase=*/false,
1074 /*delegating=*/false, curAddr, type);
1075 cir::YieldOp::create(b, l);
1076 };
1077 if (needsPartialArrayCleanup)
1078 emitPartialDtorBody = partialDtorBuilder;
1079
1080 if (useDynamicArrayCtor) {
1081 cir::ArrayCtor::create(builder, loc, dynamicElPtr, numElements,
1082 emitCtorBody, emitPartialDtorBody);
1083 } else {
1084 cir::ArrayType arrayTy =
1085 cir::ArrayType::get(elementType, constElementCount);
1086 mlir::Value arrayOp =
1087 builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
1088 cir::ArrayCtor::create(builder, loc, arrayOp, emitCtorBody,
1089 emitPartialDtorBody);
1090 }
1091}
1092
1094 const CXXConstructorDecl *ctor, CXXCtorType ctorType,
1095 const FunctionArgList &args, SourceLocation loc) {
1096 CallArgList delegateArgs;
1097
1098 FunctionArgList::const_iterator i = args.begin(), e = args.end();
1099 assert(i != e && "no parameters to constructor");
1100
1101 // this
1102 Address thisAddr = loadCXXThisAddress();
1103 delegateArgs.add(RValue::get(thisAddr.getPointer()), (*i)->getType());
1104 ++i;
1105
1106 // FIXME: The location of the VTT parameter in the parameter list is specific
1107 // to the Itanium ABI and shouldn't be hardcoded here.
1108 if (cgm.getCXXABI().needsVTTParameter(curGD)) {
1109 cgm.errorNYI(loc, "emitDelegateCXXConstructorCall: VTT parameter");
1110 return;
1111 }
1112
1113 // Explicit arguments.
1114 for (; i != e; ++i) {
1115 const VarDecl *param = *i;
1116 // FIXME: per-argument source location
1117 emitDelegateCallArg(delegateArgs, param, loc);
1118 }
1119
1121
1122 emitCXXConstructorCall(ctor, ctorType, /*ForVirtualBase=*/false,
1123 /*Delegating=*/true, thisAddr, delegateArgs, loc);
1124}
1125
1127 const auto *assignOp = cast<CXXMethodDecl>(curGD.getDecl());
1128 assert(assignOp->isCopyAssignmentOperator() ||
1129 assignOp->isMoveAssignmentOperator());
1130 const Stmt *rootS = assignOp->getBody();
1131 assert(isa<CompoundStmt>(rootS) &&
1132 "Body of an implicit assignment operator should be compound stmt.");
1133 const auto *rootCS = cast<CompoundStmt>(rootS);
1134
1135 cgm.setFuncInfoAttr(cast<cir::FuncOp>(curFn), assignOp);
1136
1139
1140 AssignmentMemcpyizer AM(*this, assignOp, args);
1141 for (auto *i : rootCS->body())
1142 AM.emitAssignment(i);
1143 AM.finish();
1144}
1145
1147 const CXXMethodDecl *callOperator, CallArgList &callArgs) {
1148 // Get the address of the call operator.
1149 const CIRGenFunctionInfo &calleeFnInfo =
1150 cgm.getTypes().arrangeCXXMethodDeclaration(callOperator);
1151 cir::FuncOp calleePtr = cgm.getAddrOfFunction(
1152 GlobalDecl(callOperator), cgm.getTypes().getFunctionType(calleeFnInfo));
1153
1154 // Prepare the return slot.
1155 const FunctionProtoType *fpt =
1156 callOperator->getType()->castAs<FunctionProtoType>();
1157 QualType resultType = fpt->getReturnType();
1158 ReturnValueSlot returnSlot;
1159 // This should also be tracking volatile, unused, and externally destructed.
1161 // For aggregate returns, write the callee's result directly into the
1162 // static invoker's return slot. Otherwise emitReturnOfRValue below would
1163 // aggregate-copy a temporary into returnValue, which is incorrect for
1164 // types without a trivial copy/move (e.g. std::string) -- and trips an
1165 // assertion in emitAggregateCopy.
1166 if (!resultType->isVoidType() && hasAggregateEvaluationKind(resultType))
1167 returnSlot = ReturnValueSlot(returnValue);
1168
1169 // We don't need to separately arrange the call arguments because
1170 // the call can't be variadic anyway --- it's impossible to forward
1171 // variadic arguments.
1172
1173 // Now emit our call.
1174 CIRGenCallee callee =
1175 CIRGenCallee::forDirect(calleePtr, GlobalDecl(callOperator));
1176 RValue rv = emitCall(calleeFnInfo, callee, returnSlot, callArgs,
1177 /*isMustTail=*/false);
1178
1179 // Forward the returned value through the function's return slot.
1180 if (!resultType->isVoidType()) {
1181 if (returnSlot.isNull() && getLangOpts().ObjCAutoRefCount &&
1182 resultType->isObjCRetainableType())
1183 cgm.errorNYI(callOperator->getSourceRange(),
1184 "emitForwardingCallToLambda: ObjCAutoRefCount");
1185 emitReturnOfRValue(getLoc(*currSrcLoc), rv, resultType);
1186 } else {
1187 cir::ReturnOp::create(builder, getLoc(*currSrcLoc));
1188 }
1189}
1190
1192 const CXXRecordDecl *lambda = md->getParent();
1193
1194 // Start building arguments for forwarding call
1195 CallArgList callArgs;
1196
1197 QualType lambdaType = getContext().getCanonicalTagType(lambda);
1198 QualType thisType = getContext().getPointerType(lambdaType);
1199 Address thisPtr =
1200 createMemTemp(lambdaType, getLoc(md->getSourceRange()), "unused.capture");
1201 callArgs.add(RValue::get(thisPtr.getPointer()), thisType);
1202
1203 // Add the rest of the parameters.
1204 for (auto *param : md->parameters())
1205 emitDelegateCallArg(callArgs, param, param->getBeginLoc());
1206
1207 const CXXMethodDecl *callOp = lambda->getLambdaCallOperator();
1208 // For a generic lambda, find the corresponding call operator specialization
1209 // to which the call to the static-invoker shall be forwarded.
1210 if (lambda->isGenericLambda()) {
1213 FunctionTemplateDecl *callOpTemplate =
1215 llvm::FoldingSetInsertToken InsertToken;
1216 FunctionDecl *correspondingCallOpSpecialization =
1217 callOpTemplate->findSpecialization(tal->asArray(), InsertToken);
1218 assert(correspondingCallOpSpecialization);
1219 callOp = cast<CXXMethodDecl>(correspondingCallOpSpecialization);
1220 }
1221 emitForwardingCallToLambda(callOp, callArgs);
1222}
1223
1225 if (md->isVariadic()) {
1226 // Codgen for LLVM doesn't emit code for this as well, it says:
1227 // FIXME: Making this work correctly is nasty because it requires either
1228 // cloning the body of the call operator or making the call operator
1229 // forward.
1230 cgm.errorNYI(md->getSourceRange(), "emitLambdaStaticInvokeBody: variadic");
1231 }
1232
1234}
1235
1237 QualType type) {
1238 const auto *record = type->castAsCXXRecordDecl();
1239 const CXXDestructorDecl *dtor = record->getDestructor();
1240 // TODO(cir): Unlike traditional codegen, CIRGen should actually emit trivial
1241 // dtors which shall be removed on later CIR passes. However, only remove this
1242 // assertion after we have a test case to exercise this path.
1243 assert(!dtor->isTrivial());
1244 cgf.emitCXXDestructorCall(dtor, Dtor_Complete, /*forVirtualBase*/ false,
1245 /*delegating=*/false, addr, type);
1246}
1247
1249 if (Expr *thisArg = dd->getOperatorDeleteThisArg())
1250 return emitScalarExpr(thisArg);
1251 return loadCXXThis();
1252}
1253
1254namespace {
1255/// Call the operator delete associated with the current destructor.
1256struct CallDtorDelete final : EHScopeStack::Cleanup {
1257 CallDtorDelete() {}
1258
1259 void emit(CIRGenFunction &cgf, Flags flags) override {
1261 const CXXRecordDecl *classDecl = dtor->getParent();
1263 cgf.loadThisForDtorDelete(dtor),
1264 cgf.getContext().getCanonicalTagType(classDecl));
1265 }
1266};
1267
1268class DestroyField final : public EHScopeStack::Cleanup {
1269 const FieldDecl *field;
1270 CIRGenFunction::Destroyer *destroyer;
1271
1272public:
1273 DestroyField(const FieldDecl *field, CIRGenFunction::Destroyer *destroyer)
1274 : field(field), destroyer(destroyer) {}
1275
1276 void emit(CIRGenFunction &cgf, Flags flags) override {
1277 // Find the address of the field.
1278 Address thisValue = cgf.loadCXXThisAddress();
1279 CanQualType recordTy =
1280 cgf.getContext().getCanonicalTagType(field->getParent());
1281 LValue thisLV = cgf.makeAddrLValue(thisValue, recordTy);
1282 LValue lv = cgf.emitLValueForField(thisLV, field);
1283 assert(lv.isSimple());
1284
1286 cgf.emitDestroy(lv.getAddress(), field->getType(), destroyer);
1287 }
1288};
1289} // namespace
1290
1291/// Emit all code that comes at the end of class's destructor. This is to call
1292/// destructors on members and base classes in reverse order of their
1293/// construction.
1294///
1295/// For a deleting destructor, this pushes the cleanup that calls operator
1296/// delete. The caller handles a destroying operator delete.
1298 CXXDtorType dtorType) {
1299 assert((!dd->isTrivial() || dd->hasAttr<DLLExportAttr>()) &&
1300 "Should not emit dtor epilogue for non-exported trivial dtor!");
1301
1302 // The deleting-destructor phase just needs to call the appropriate
1303 // operator delete that Sema picked up.
1304 if (dtorType == Dtor_Deleting) {
1305 assert(dd->getOperatorDelete() &&
1306 "operator delete missing - EnterDtorCleanups");
1308 // The implicit parameter of a deleting destructor is the Microsoft ABI
1309 // flag word that selects whether and which operator delete is called.
1310 assert(getTarget().getCXXABI().isMicrosoft() &&
1311 "only the Microsoft ABI passes an implicit deleting dtor param");
1312 cgm.errorNYI(dd->getSourceRange(),
1313 "deleting destructor with conditional delete: MSVC ABI");
1314
1315 } else {
1317 "destroying operator delete is handled by emitDestructorBody");
1318 ehStack.pushCleanup<CallDtorDelete>(NormalAndEHCleanup);
1319 }
1320 return;
1321 }
1322
1323 const CXXRecordDecl *classDecl = dd->getParent();
1324
1325 // Unions have no bases and do not call field destructors.
1326 if (classDecl->isUnion())
1327 return;
1328
1329 // The complete-destructor phase just destructs all the virtual bases.
1330 if (dtorType == Dtor_Complete) {
1332
1333 // We push them in the forward order so that they'll be popped in
1334 // the reverse order.
1335 for (const CXXBaseSpecifier &base : classDecl->vbases()) {
1336 auto *baseClassDecl = base.getType()->castAsCXXRecordDecl();
1337
1338 if (baseClassDecl->hasTrivialDestructor()) {
1339 // Under SanitizeMemoryUseAfterDtor, poison the trivial base class
1340 // memory. For non-trival base classes the same is done in the class
1341 // destructor.
1343 } else {
1344 ehStack.pushCleanup<CallBaseDtor>(NormalAndEHCleanup, baseClassDecl,
1345 /*baseIsVirtual=*/true);
1346 }
1347 }
1348
1349 return;
1350 }
1351
1352 assert(dtorType == Dtor_Base);
1354
1355 // Destroy non-virtual bases.
1356 for (const CXXBaseSpecifier &base : classDecl->bases()) {
1357 // Ignore virtual bases.
1358 if (base.isVirtual())
1359 continue;
1360
1361 CXXRecordDecl *baseClassDecl = base.getType()->getAsCXXRecordDecl();
1362
1363 if (baseClassDecl->hasTrivialDestructor())
1365 else
1366 ehStack.pushCleanup<CallBaseDtor>(NormalAndEHCleanup, baseClassDecl,
1367 /*baseIsVirtual=*/false);
1368 }
1369
1371
1372 // Destroy direct fields.
1373 for (const FieldDecl *field : classDecl->fields()) {
1374 QualType type = field->getType();
1375 QualType::DestructionKind dtorKind = type.isDestructedType();
1376 if (!dtorKind)
1377 continue;
1378
1379 // Anonymous union members do not have their destructors called.
1380 const RecordType *rt = type->getAsUnionType();
1381 if (rt && rt->getDecl()->isAnonymousStructOrUnion())
1382 continue;
1383
1384 CleanupKind cleanupKind = getCleanupKind(dtorKind);
1386 ehStack.pushCleanup<DestroyField>(cleanupKind, field,
1387 getDestroyer(dtorKind));
1388 }
1389}
1390
1392 const CXXConstructorDecl *ctor, const FunctionArgList &args) {
1393 assert(ctor->isDelegatingConstructor());
1394
1395 Address thisPtr = loadCXXThisAddress();
1396
1403
1404 emitAggExpr(ctor->init_begin()[0]->getInit(), aggSlot);
1405
1406 const CXXRecordDecl *classDecl = ctor->getParent();
1407 if (cgm.getLangOpts().Exceptions && !classDecl->hasTrivialDestructor()) {
1408 CXXDtorType dtorType =
1409 curGD.getCtorType() == Ctor_Complete ? Dtor_Complete : Dtor_Base;
1410 ehStack.pushCleanup<CallDelegatingCtorDtor>(
1411 EHCleanup, classDecl->getDestructor(), thisPtr, dtorType);
1412 }
1413}
1414
1417 bool forVirtualBase, bool delegating,
1418 Address thisAddr, QualType thisTy) {
1419 cgm.getCXXABI().emitDestructorCall(*this, dd, type, forVirtualBase,
1420 delegating, thisAddr, thisTy);
1421}
1422
1423mlir::Value CIRGenFunction::getVTTParameter(GlobalDecl gd, bool forVirtualBase,
1424 bool delegating) {
1425 if (!cgm.getCXXABI().needsVTTParameter(gd))
1426 return nullptr;
1427
1428 const CXXRecordDecl *rd = cast<CXXMethodDecl>(curCodeDecl)->getParent();
1429 const CXXRecordDecl *base = cast<CXXMethodDecl>(gd.getDecl())->getParent();
1430
1431 uint64_t subVTTIndex;
1432
1433 if (delegating) {
1434 // If this is a delegating constructor call, just load the VTT.
1435 return loadCXXVTT();
1436 } else if (rd == base) {
1437 // If the record matches the base, this is the complete ctor/dtor
1438 // variant calling the base variant in a class with virtual bases.
1439 assert(!cgm.getCXXABI().needsVTTParameter(curGD) &&
1440 "doing no-op VTT offset in base dtor/ctor?");
1441 assert(!forVirtualBase && "Can't have same class as virtual base!");
1442 subVTTIndex = 0;
1443 } else {
1444 const ASTRecordLayout &layout = getContext().getASTRecordLayout(rd);
1445 CharUnits baseOffset = forVirtualBase ? layout.getVBaseClassOffset(base)
1446 : layout.getBaseClassOffset(base);
1447
1448 subVTTIndex =
1449 cgm.getVTables().getSubVTTIndex(rd, BaseSubobject(base, baseOffset));
1450 assert(subVTTIndex != 0 && "Sub-VTT index must be greater than zero!");
1451 }
1452
1453 mlir::Location loc = cgm.getLoc(rd->getBeginLoc());
1454 if (cgm.getCXXABI().needsVTTParameter(curGD)) {
1455 // A VTT parameter was passed to the constructor, use it.
1456 mlir::Value vtt = loadCXXVTT();
1457 return builder.createVTTAddrPoint(loc, vtt.getType(), vtt, subVTTIndex);
1458 } else {
1459 // We're the complete constructor, so get the VTT by name.
1460 cir::GlobalOp vtt = cgm.getVTables().getAddrOfVTT(rd);
1461 mlir::Type voidPtrTy = convertType(getContext().VoidPtrTy);
1462 cir::PointerType vttTy =
1463 builder.getPointerTo(voidPtrTy, vtt.getAddrSpaceAttr());
1464 auto vttSym = mlir::FlatSymbolRefAttr::get(vtt.getSymNameAttr());
1465 return builder.createVTTAddrPoint(loc, vttTy, vttSym, subVTTIndex);
1466 }
1467}
1468
1470 mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived,
1471 llvm::iterator_range<CastExpr::path_const_iterator> path,
1472 bool nullCheckValue) {
1473 assert(!path.empty() && "Base path should not be empty!");
1474
1475 QualType derivedTy = getContext().getCanonicalTagType(derived);
1476 mlir::Type derivedValueTy = convertType(derivedTy);
1477 CharUnits nonVirtualOffset =
1478 cgm.computeNonVirtualBaseClassOffset(derived, path);
1479
1480 // Note that in OG, no offset (nonVirtualOffset.getQuantity() == 0) means it
1481 // just gives the address back. In CIR a `cir.derived_class` is created and
1482 // made into a nop later on during lowering.
1483 return builder.createDerivedClassAddr(loc, baseAddr, derivedValueTy,
1484 nonVirtualOffset.getQuantity(),
1485 /*assumeNotNull=*/!nullCheckValue);
1486}
1487
1489 Address value, const CXXRecordDecl *derived,
1490 llvm::iterator_range<CastExpr::path_const_iterator> path,
1491 bool nullCheckValue, SourceLocation loc) {
1492 assert(!path.empty() && "Base path should not be empty!");
1493
1494 CastExpr::path_const_iterator start = path.begin();
1495 const CXXRecordDecl *vBase = nullptr;
1496
1497 if ((*path.begin())->isVirtual()) {
1498 vBase = (*start)->getType()->castAsCXXRecordDecl();
1499 ++start;
1500 }
1501
1502 // Compute the static offset of the ultimate destination within its
1503 // allocating subobject (the virtual base, if there is one, or else
1504 // the "complete" object that we see).
1505 CharUnits nonVirtualOffset = cgm.computeNonVirtualBaseClassOffset(
1506 vBase ? vBase : derived, {start, path.end()});
1507
1508 // If there's a virtual step, we can sometimes "devirtualize" it.
1509 // For now, that's limited to when the derived type is final.
1510 // TODO: "devirtualize" this for accesses to known-complete objects.
1511 if (vBase && derived->hasAttr<FinalAttr>()) {
1512 const ASTRecordLayout &layout = getContext().getASTRecordLayout(derived);
1513 CharUnits vBaseOffset = layout.getVBaseClassOffset(vBase);
1514 nonVirtualOffset += vBaseOffset;
1515 vBase = nullptr; // we no longer have a virtual step
1516 }
1517
1518 // Get the base pointer type.
1519 mlir::Type baseValueTy = convertType((path.end()[-1])->getType());
1520
1521 // If there is no virtual base, use cir.base_class_addr. It takes care of
1522 // the adjustment and the null pointer check.
1523 if (nonVirtualOffset.isZero() && !vBase) {
1525 return builder.createBaseClassAddr(getLoc(loc), value, baseValueTy, 0,
1526 /*assumeNotNull=*/true);
1527 }
1528
1530
1531 mlir::Location mlirLoc = getLoc(loc);
1532
1533 // Computing the virtual offset requires reading the vtable, which is only
1534 // safe to do once we know the pointer isn't null. Guard the whole
1535 // computation, mirroring classic CodeGen's cast.notnull/cast.end split.
1536 if (vBase && nullCheckValue) {
1537 CharUnits alignment =
1538 cgm.getVBaseAlignment(value.getAlignment(), derived, vBase)
1539 .alignmentAtOffset(nonVirtualOffset);
1540 mlir::Type basePtrTy =
1541 builder.getPointerTo(baseValueTy, value.getAddressSpace());
1542 mlir::Value ptrIsNull = builder.createPtrIsNull(value.getPointer());
1543 mlir::Value result =
1544 cir::TernaryOp::create(
1545 builder, mlirLoc, ptrIsNull,
1546 [&](mlir::OpBuilder &, mlir::Location) {
1547 builder.createYield(
1548 mlirLoc, builder.getNullPtr(basePtrTy, mlirLoc).getResult());
1549 },
1550 [&](mlir::OpBuilder &, mlir::Location) {
1551 mlir::Value virtualOffset =
1552 cgm.getCXXABI().getVirtualBaseClassOffset(
1553 mlirLoc, *this, value, derived, vBase);
1555 mlirLoc, *this, value, nonVirtualOffset, virtualOffset,
1556 derived, vBase, baseValueTy, /*assumeNotNull=*/true);
1557 adjusted = adjusted.withElementType(builder, baseValueTy);
1558 builder.createYield(mlirLoc, adjusted.getPointer());
1559 })
1560 .getResult();
1561 return Address(result, baseValueTy, alignment);
1562 }
1563
1564 // Compute the virtual offset.
1565 mlir::Value virtualOffset = nullptr;
1566 if (vBase) {
1567 virtualOffset = cgm.getCXXABI().getVirtualBaseClassOffset(
1568 mlirLoc, *this, value, derived, vBase);
1569 }
1570
1571 // Apply both offsets.
1573 mlirLoc, *this, value, nonVirtualOffset, virtualOffset, derived, vBase,
1574 baseValueTy, not nullCheckValue);
1575
1576 // Cast to the destination type.
1577 value = value.withElementType(builder, baseValueTy);
1578
1579 return value;
1580}
1581
1582// TODO(cir): this can be shared with LLVM codegen.
1585 if (!cgm.getCodeGenOpts().WholeProgramVTables)
1586 return false;
1587
1588 if (cgm.getCodeGenOpts().VirtualFunctionElimination)
1589 return true;
1590
1592
1593 return false;
1594}
1595
1596mlir::Value CIRGenFunction::getVTablePtr(mlir::Location loc, Address thisAddr,
1597 const CXXRecordDecl *rd) {
1598 auto vtablePtr =
1599 cir::VTableGetVPtrOp::create(builder, loc, thisAddr.getPointer());
1600 Address vtablePtrAddr = Address(vtablePtr, thisAddr.getAlignment());
1601
1602 auto vtable = builder.createLoad(loc, vtablePtrAddr);
1604
1605 if (cgm.getCodeGenOpts().OptimizationLevel > 0 &&
1606 cgm.getCodeGenOpts().StrictVTablePointers) {
1608 }
1609
1610 return vtable;
1611}
1612
1615 bool forVirtualBase,
1616 bool delegating,
1617 AggValueSlot thisAVS,
1618 const clang::CXXConstructExpr *e) {
1619 Address thisAddr = thisAVS.getAddress();
1620 QualType thisType = d->getThisType();
1621 mlir::Value thisPtr = thisAddr.getPointer();
1622
1624
1625 // If this is a trivial constructor, just emit what's needed. If this is a
1626 // union copy constructor, we must emit a memcpy, because the AST does not
1627 // model that copy.
1629 assert(e->getNumArgs() == 1 && "unexpected argcount for trivial ctor");
1630 const Expr *arg = e->getArg(0);
1631 LValue src = emitLValue(arg);
1633 LValue dest = makeAddrLValue(thisAddr, destTy);
1634 emitAggregateCopy(dest, src, src.getType(), thisAVS.mayOverlap());
1635 return;
1636 }
1637
1638 CallArgList args;
1639 args.add(RValue::get(thisPtr), thisType);
1640
1641 const FunctionProtoType *fpt = d->getType()->castAs<FunctionProtoType>();
1642
1644 ? EvaluationOrder::ForceLeftToRight
1645 : EvaluationOrder::Default;
1646
1647 if (auto inherited = d->getInheritedConstructor();
1648 !inherited || cgm.getTypes().inheritingCtorHasParams(inherited, type))
1649 emitCallArgs(args, fpt, e->arguments(), e->getConstructor(),
1650 /*ParamsToSkip=*/0, order);
1651
1653 emitCXXConstructorCall(d, type, forVirtualBase, delegating, thisAddr, args,
1654 e->getExprLoc());
1655}
1656
1658 const CXXConstructorDecl *d,
1659 CXXCtorType type) {
1660 // We can't forward a variadic call.
1661 if (d->isVariadic())
1662 return false;
1663
1665 // FIXME(CIR): It isn't clear to me that this is the right answer here,
1666 // classic-codegen decides the answer is 'false' if there is an inalloca
1667 // argument or if there is a param that needs destruction.
1668 // When we get an understanding of what the the calling-convention code
1669 // needs here, we should be able to replace this with either a 'return
1670 // false' or 'return true'.
1671 // Perhaps we should be checking isParamDestroyedInCallee?
1672 cgm.errorNYI(d->getSourceRange(),
1673 "canEmitDelegateCallArgs: args-destroyed-L-to-R in callee");
1674 }
1675
1676 return true;
1677}
1678
1680 const CXXConstructorDecl *d, bool forVirtualBase, Address thisAddr,
1681 bool inheritedFromVBase, const CXXInheritedCtorInitExpr *e) {
1682
1683 CallArgList ctorArgs;
1685 thisAddr, d->getThisType()->getPointeeType())),
1686 d->getThisType());
1687
1688 if (inheritedFromVBase &&
1689 cgm.getTarget().getCXXABI().hasConstructorVariants()) {
1690 // The base-object variant doesn't construct virtual bases, so the
1691 // inherited constructor's arguments aren't passed.
1692 ctorArgs.push_back(thisArg);
1693 } else if (!cxxInheritedCtorInitExprArgs.empty()) {
1694 // The inheriting constructor was inlined; just inject its arguments.
1695 assert(cxxInheritedCtorInitExprArgs.size() >= d->getNumParams() &&
1696 "wrong number of parameters for inherited constructor call");
1698 ctorArgs[0] = thisArg;
1699 } else {
1700 ctorArgs.push_back(thisArg);
1701 const auto *outerCtor = cast<CXXConstructorDecl>(curCodeDecl);
1702 assert(outerCtor->getNumParams() == d->getNumParams());
1703 assert(!outerCtor->isVariadic() && "should have been inlined");
1704
1705 for (const ParmVarDecl *param : outerCtor->parameters()) {
1706 assert(getContext().hasSameUnqualifiedType(
1707 outerCtor->getParamDecl(param->getFunctionScopeIndex())->getType(),
1708 param->getType()));
1709 emitDelegateCallArg(ctorArgs, param, e->getLocation());
1710
1711 if (param->hasAttr<PassObjectSizeAttr>())
1712 cgm.errorNYI(
1713 e->getLocation(),
1714 "emitInheritedCXXConstructorCall: pass object size attr argument");
1715 }
1716 }
1717
1718 emitCXXConstructorCall(d, Ctor_Base, forVirtualBase, /*delegating=*/false,
1719 thisAddr, ctorArgs, e->getLocation());
1720}
1721
1723 SourceLocation loc, const CXXConstructorDecl *d, CXXCtorType ctorType,
1724 bool forVirtualBase, bool delegating, CallArgList &args) {
1725 GlobalDecl gd(d, ctorType);
1727 SymTableScopeTy varScope(symbolTable);
1728 InlinedInheritingConstructorScope scope(*this, gd);
1729 RunCleanupsScope RunCleanups(*this);
1730
1731 // Save the arguments to be passed to the inherited constructor.
1733
1734 FunctionArgList params;
1735 QualType retTy = buildFunctionArgList(gd, params);
1736 // FIXME(cir): When we get to the !isVoidType NYI below, this probably is
1737 // going to be important. In the meantime, this is likely not really doing
1738 // anything.
1739 fnRetTy = retTy;
1740
1741 cgm.getCXXABI().addImplicitConstructorArgs(*this, d, ctorType, forVirtualBase,
1742 delegating, args);
1743
1744 // Emit a simplified prolog. We only need to emit the implicit params.
1745 assert(args.size() >= params.size() && "too few arguments for call");
1746 for (auto [idx, arg, parm] :
1747 llvm::zip_longest(llvm::index_range{0, args.size()}, args, params)) {
1748 if (idx < params.size() && isa<ImplicitParamDecl>(*parm)) {
1749 mlir::Location parmLoc = getLoc((*parm)->getSourceRange());
1750 RValue argVal = arg->getRValue(*this, parmLoc);
1751
1752 LValue allocaVal = makeAddrLValue(
1753 createTempAlloca(convertType((*parm)->getType()),
1754 getContext().getDeclAlign(*parm), parmLoc),
1755 (*parm)->getType());
1756
1757 emitStoreThroughLValue(argVal, allocaVal, /*isInit=*/true);
1758
1759 setAddrOfLocalVar((*parm), allocaVal.getAddress());
1760 }
1761 }
1762
1763 // FIXME(cir): it isn't clear what it takes to get here with a constructor?
1764 // Leave as an NYI until we come across a reproducer.
1765 if (!retTy->isVoidType())
1766 cgm.errorNYI(d->getSourceRange(),
1767 "emitInlinedInheritingCXXConstructorCall: non-void return");
1768
1769 cgm.getCXXABI().emitInstanceFunctionProlog(loc, *this);
1771 emitCtorPrologue(d, ctorType, params);
1772}
1773
1775 const CXXConstructorDecl *d, CXXCtorType type, bool forVirtualBase,
1776 bool delegating, Address thisAddr, CallArgList &args, SourceLocation loc) {
1777
1778 const CXXRecordDecl *crd = d->getParent();
1779
1780 // If this is a call to a trivial default constructor:
1781 // In LLVM: do nothing.
1782 // In CIR: emit as a regular call, other later passes should lower the
1783 // ctor call into trivial initialization.
1785
1786 // Note: memcpy-equivalent special members are handled in the
1787 // emitCXXConstructorCall overload that takes a CXXConstructExpr.
1788
1789 bool passPrototypeArgs = true;
1790
1791 // Check whether we can actually emit the constructor before trying to do so.
1792 if (auto inherited = d->getInheritedConstructor()) {
1793 passPrototypeArgs = getTypes().inheritingCtorHasParams(inherited, type);
1794 if (passPrototypeArgs &&
1795 !canEmitDelegateCallArgs(cgm, cgm.getASTContext(), d, type)) {
1796 emitInlinedInheritingCXXConstructorCall(loc, d, type, forVirtualBase,
1797 delegating, args);
1798 return;
1799 }
1800 }
1801
1802 // Insert any ABI-specific implicit constructor arguments.
1804 cgm.getCXXABI().addImplicitConstructorArgs(*this, d, type, forVirtualBase,
1805 delegating, args);
1806
1807 // Emit the call.
1808 auto calleePtr = cgm.getAddrOfCXXStructor(GlobalDecl(d, type));
1809 const CIRGenFunctionInfo &info = cgm.getTypes().arrangeCXXConstructorCall(
1810 args, d, type, extraArgs.prefix, extraArgs.suffix, passPrototypeArgs);
1811 CIRGenCallee callee = CIRGenCallee::forDirect(calleePtr, GlobalDecl(d, type));
1812 cir::CIRCallOpInterface c;
1813 emitCall(info, callee, ReturnValueSlot(), args, &c, /*isMustTail=*/false,
1814 loc);
1815
1816 if (cgm.getCodeGenOpts().OptimizationLevel != 0 && !crd->isDynamicClass() &&
1817 type != Ctor_Base && cgm.getCodeGenOpts().StrictVTablePointers)
1818 cgm.errorNYI(d->getSourceRange(), "vtable assumption loads");
1819}
static bool emit(llvm::SmallVectorImpl< std::byte > &Code, const T &Val)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static Address applyNonVirtualAndVirtualOffset(mlir::Location loc, CIRGenFunction &cgf, Address addr, CharUnits nonVirtualOffset, mlir::Value virtualOffset, const CXXRecordDecl *derivedClass, const CXXRecordDecl *nearestVBase, mlir::Type baseValueTy={}, bool assumeNotNull=true)
static void emitMemberInitializer(CIRGenFunction &cgf, const CXXRecordDecl *classDecl, CXXCtorInitializer *memberInit, const CXXConstructorDecl *constructor, FunctionArgList &args)
static bool canEmitDelegateCallArgs(CIRGenModule &cgm, ASTContext &ctx, const CXXConstructorDecl *d, CXXCtorType type)
static void emitLValueForAnyFieldInitialization(CIRGenFunction &cgf, CXXCtorInitializer *memberInit, LValue &lhs)
Defines the clang::Expr interface and subclasses for C++ expressions.
C Language Family Type Representation.
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:974
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType getCanonicalTagType(const TagDecl *TD) const
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getSize() const
getSize - Get the record size in characters.
CharUnits getNonVirtualAlignment() const
getNonVirtualAlignment - Get the non-virtual alignment (in chars) of an object, which is the alignmen...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
mlir::ptr::MemorySpaceAttrInterface getAddressSpace() const
Definition Address.h:133
mlir::Value getPointer() const
Definition Address.h:98
mlir::Type getElementType() const
Definition Address.h:125
static Address invalid()
Definition Address.h:76
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const
Return address with different element type, a bitcast pointer, and the same alignment.
clang::CharUnits getAlignment() const
Definition Address.h:138
bool isValid() const
Definition Address.h:77
An aggregate value slot.
Overlap_t mayOverlap() const
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false, bool isNontemporal=false)
Address createBaseClassAddr(mlir::Location loc, Address addr, mlir::Type destType, unsigned offset, bool assumeNotNull)
cir::MemCpyOp createMemCpy(mlir::Location loc, Address dst, Address src, mlir::Value len)
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, FunctionArgList &args) const =0
static CIRGenCallee forDirect(mlir::Operation *funcPtr, const CIRGenCalleeInfo &abstractInfo=CIRGenCalleeInfo())
Definition CIRGenCall.h:92
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
static bool isConstructorDelegationValid(const clang::CXXConstructorDecl *ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md)
mlir::Type convertType(clang::QualType t)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
Address emitCXXMemberDataPointerAddress(const Expr *e, Address base, mlir::Value memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo)
CIRGenTypes & getTypes() const
const clang::LangOptions & getLangOpts() const
cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)
This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...
void emitForwardingCallToLambda(const CXXMethodDecl *lambdaCallOperator, CallArgList &callArgs)
mlir::Value loadCXXThis()
Load the value for 'this'.
LValue makeNaturalAlignPointeeAddrLValue(mlir::Value v, clang::QualType t)
Given a value of type T* that may not be to a complete object, construct an l-vlaue withi the natural...
void emitDeleteCall(const FunctionDecl *deleteFD, mlir::Value ptr, QualType deleteTy)
const TargetInfo & getTarget() const
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
const clang::Decl * curFuncDecl
void emitInlinedInheritingCXXConstructorCall(SourceLocation loc, const CXXConstructorDecl *d, CXXCtorType ctorType, bool forVirtualBase, bool delegating, CallArgList &args)
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
void emitAggregateCopy(LValue dest, LValue src, QualType eltTy, AggValueSlot::Overlap_t mayOverlap, bool isVolatile=false)
Emit an aggregate copy.
LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty)
mlir::Value getVTTParameter(GlobalDecl gd, bool forVirtualBase, bool delegating)
Return the VTT parameter that should be passed to a base constructor/destructor with virtual bases.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void initializeVTablePointers(mlir::Location loc, const clang::CXXRecordDecl *rd)
CodeGenUtils::EvaluationOrder EvaluationOrder
void initializeVTablePointer(mlir::Location loc, const VPtr &vptr)
void emitCallArgs(CallArgList &args, PrototypeWrapper prototype, llvm::iterator_range< clang::CallExpr::const_arg_iterator > argRange, AbstractCallee callee=AbstractCallee(), unsigned paramsToSkip=0, EvaluationOrder order=EvaluationOrder::Default)
Address getAddressOfBaseClass(Address value, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue, SourceLocation loc)
void emitDelegateCXXConstructorCall(const clang::CXXConstructorDecl *ctor, clang::CXXCtorType ctorType, const FunctionArgList &args, clang::SourceLocation loc)
void emitBaseInitializer(mlir::Location loc, const CXXRecordDecl *classDecl, CXXCtorInitializer *baseInit)
void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d, LValue lvalue, bool capturedByInit=false)
Emit an expression as an initializer for an object (variable, field, etc.) at the given location.
mlir::Value emitArrayLength(const clang::ArrayType *arrayType, QualType &baseType, Address &addr)
Computes the length of an array in elements, as well as the base element type and a properly-typed fi...
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
VPtrsVector getVTablePointers(const clang::CXXRecordDecl *vtableClass)
llvm::ScopedHashTableScope< const clang::Decl *, mlir::Value > SymTableScopeTy
CleanupKind getCleanupKind(QualType::DestructionKind kind)
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
mlir::Operation * curFn
The current function or global initializer that is generated code for.
Address getAddressOfDerivedClass(mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue)
CallArgList cxxInheritedCtorInitExprArgs
The values of function arguments to use when evaluating CXXInheritedCtorInitExprs within this context...
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
void enterDtorCleanups(const CXXDestructorDecl *dtor, CXXDtorType type)
Enter the cleanups necessary to complete the given phase of destruction for a destructor.
void emitImplicitAssignmentOperatorBody(FunctionArgList &args)
static int64_t getZExtIntValueFromConstOp(mlir::Value val)
Get zero-extended integer from a mlir::Value that is an int constant or a constant op.
mlir::Type convertTypeForMem(QualType t)
clang::QualType buildFunctionArgList(clang::GlobalDecl gd, FunctionArgList &args)
void emitCtorPrologue(const clang::CXXConstructorDecl *ctor, clang::CXXCtorType ctorType, FunctionArgList &args)
This routine generates necessary code to initialize base classes and non-static data members belongin...
mlir::Value loadCXXVTT()
Load the VTT parameter to base constructors/destructors have virtual bases.
Address returnValue
The temporary alloca to hold the return value.
void emitCXXConstructorCall(const clang::CXXConstructorDecl *d, clang::CXXCtorType type, bool forVirtualBase, bool delegating, AggValueSlot thisAVS, const clang::CXXConstructExpr *e)
static bool hasAggregateEvaluationKind(clang::QualType type)
mlir::Value getVTablePtr(mlir::Location loc, Address thisAddr, const clang::CXXRecordDecl *vtableClass)
Return the Value of the vtable pointer member pointed to by thisAddr.
llvm::SmallPtrSet< const clang::CXXRecordDecl *, 4 > VisitedVirtualBasesSetTy
void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty)
bool shouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *rd)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
const clang::Decl * curCodeDecl
This is the inner-most code context, which includes blocks.
LValue emitLValueForFieldInitialization(LValue base, const clang::FieldDecl *field, llvm::StringRef fieldName)
Like emitLValueForField, excpet that if the Field is a reference, this will return the address of the...
mlir::Value getAsNaturalPointerTo(Address addr, QualType pointeeType)
void emitInitializerForField(clang::FieldDecl *field, LValue lhs, clang::Expr *init)
mlir::Value loadThisForDtorDelete(const CXXDestructorDecl *dd)
Return the pointer to pass to the operator delete of the given destructor, converted to the type of i...
LValue emitLValueForField(LValue base, const clang::FieldDecl *field)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
Address getAddressOfDirectBaseInCompleteClass(mlir::Location loc, Address value, const CXXRecordDecl *derived, const CXXRecordDecl *base, bool baseIsVirtual)
Convert the given pointer to a complete class to the given direct base.
CIRGenBuilderTy & getBuilder()
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual)
Determine whether a base class initialization may overlap some other object.
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
Destroyer * getDestroyer(clang::QualType::DestructionKind kind)
void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty)
std::optional< SourceRange > currSrcLoc
Use to track source locations across nested visitor traversals.
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
void pushEHDestroyIfNeeded(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroyIfNeeded - Push the standard destructor for the given type as an EH-only cleanup.
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, bool isMustTail, SourceRange clangLoc)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
llvm::SmallVector< VPtr, 4 > VPtrsVector
void emitLambdaStaticInvokeBody(const CXXMethodDecl *md)
void emitCXXAggrConstructorCall(const CXXConstructorDecl *ctor, const clang::ArrayType *arrayType, Address arrayBegin, const CXXConstructExpr *e, bool newPointerIsChecked, bool zeroInitialize=false)
Emit a loop to call a particular constructor for each of several members of an array.
void emitDelegateCallArg(CallArgList &args, const clang::VarDecl *param, clang::SourceLocation loc)
We are performing a delegate call; that is, the current function is delegating to another one.
clang::ASTContext & getContext() const
void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
Set the address of a local variable.
void emitInheritedCXXConstructorCall(const CXXConstructorDecl *d, bool forVirtualBase, Address thisAddr, bool inheritedFromVBase, const CXXInheritedCtorInitExpr *e)
void emitStoreThroughLValue(RValue src, LValue dst, bool isInit=false)
Store the specified rvalue into the specified lvalue, where both are guaranteed to the have the same ...
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
void emitDelegatingCXXConstructorCall(const CXXConstructorDecl *ctor, const FunctionArgList &args)
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
CharUnits getDynamicOffsetAlignment(CharUnits actualBaseAlign, const CXXRecordDecl *baseDecl, CharUnits expectedTargetAlign)
TODO: Add TBAAAccessInfo.
CharUnits getMinimumClassObjectSize(const CXXRecordDecl *cd)
Returns the minimum object size for an object of the given class type (or a class derived from it).
clang::DiagnosticsEngine & getDiags() const
CharUnits getVBaseAlignment(CharUnits derivedAlign, const CXXRecordDecl *derived, const CXXRecordDecl *vbase)
Returns the assumed alignment of a virtual base of a class.
CIRGenCXXABI & getCXXABI() const
const CIRGenBitFieldInfo & getBitFieldInfo(const clang::FieldDecl *fd) const
Return the BitFieldInfo that corresponds to the field FD.
bool inheritingCtorHasParams(const InheritedConstructor &inherited, CXXCtorType type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
void add(RValue rvalue, clang::QualType type)
Definition CIRGenCall.h:241
Information for lazily generating a cleanup.
Type for representing both the decl and type of parameters to a function.
Definition CIRGenCall.h:195
Address getAddress() const
clang::QualType getType() const
bool isSimple() const
This trivial value class is used to represent the result of an expression that is evaluated.
Definition CIRGenValue.h:33
static RValue get(mlir::Value v)
Definition CIRGenValue.h:83
Contains the address where the return value of a function can be stored, and whether the address is v...
Definition CIRGenCall.h:262
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1696
arg_range arguments()
Definition ExprCXX.h:1677
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1616
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1635
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1693
Represents a C++ constructor within a class.
Definition DeclCXX.h:2645
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition DeclCXX.h:2760
bool isDelegatingConstructor() const
Determine whether this constructor is a delegating constructor.
Definition DeclCXX.h:2809
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Definition DeclCXX.cpp:3069
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
Definition DeclCXX.h:2894
Represents a C++ base or member initializer.
Definition DeclCXX.h:2410
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2612
SourceLocation getSourceLocation() const
Determine the source location of the initializer.
Definition DeclCXX.cpp:2953
bool isAnyMemberInitializer() const
Definition DeclCXX.h:2490
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2482
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2494
const Type * getBaseClass() const
If this is a base class initializer, returns the type of the base class.
Definition DeclCXX.cpp:2946
FieldDecl * getAnyMember() const
Definition DeclCXX.h:2556
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2564
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2536
Represents a C++ destructor within a class.
Definition DeclCXX.h:2924
const FunctionDecl * getOperatorDelete() const
Definition DeclCXX.cpp:3230
Expr * getOperatorDeleteThisArg() const
Definition DeclCXX.h:2963
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1756
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1809
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2296
QualType getThisType() const
Return the type of the this pointer.
Definition DeclCXX.cpp:2859
QualType getFunctionObjectParameterType() const
Definition DeclCXX.h:2320
bool isMemcpyEquivalentSpecialMember(const ASTContext &Ctx) const
Returns whether this is a copy/move constructor or assignment operator that can be implemented as a m...
Definition DeclCXX.cpp:2782
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
Definition DeclCXX.cpp:2341
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition DeclCXX.cpp:1681
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition DeclCXX.h:1382
base_class_range bases()
Definition DeclCXX.h:609
base_class_range vbases()
Definition DeclCXX.h:626
bool isAbstract() const
Determine whether this class has a pure virtual function.
Definition DeclCXX.h:1231
bool isDynamicClass() const
Definition DeclCXX.h:575
bool hasDefinition() const
Definition DeclCXX.h:562
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition DeclCXX.cpp:2129
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition DeclCXX.cpp:1744
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition DeclCXX.h:624
const CXXBaseSpecifier *const * path_const_iterator
Definition Expr.h:3812
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
Definition CharUnits.h:177
bool isZero() const
Test whether the quantity equals zero.
Definition CharUnits.h:101
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
static CharUnits One()
Construct a CharUnits quantity of one.
Definition CharUnits.h:55
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition CharUnits.h:184
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Definition CharUnits.h:52
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3858
bool hasAttr() const
Definition DeclBase.h:586
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:833
bool hasErrorOccurred() const
Definition Diagnostic.h:923
This represents one expression.
Definition Expr.h:114
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
Represents a member of a struct/union/class.
Definition Decl.h:3341
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3426
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
Definition Decl.cpp:4871
Represents a function declaration or definition.
Definition Decl.h:2082
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4283
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4271
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3627
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2947
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2546
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3139
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition Decl.cpp:4407
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2554
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4648
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3902
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5952
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
QualType getReturnType() const
Definition TypeBase.h:5084
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:60
CXXCtorType getCtorType() const
Definition GlobalDecl.h:117
const Decl * getDecl() const
Definition GlobalDecl.h:115
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3648
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3669
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3751
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Definition Type.cpp:5852
QualType getPointeeType() const
Definition TypeBase.h:3769
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:303
Represents a parameter to a function.
Definition Decl.h:1832
A (possibly-)qualified type.
Definition TypeBase.h:938
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8618
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1561
The collection of all-type qualifiers we support.
Definition TypeBase.h:332
bool hasVolatile() const
Definition TypeBase.h:468
bool hasObjCLifetime() const
Definition TypeBase.h:545
field_range fields() const
Definition Decl.h:4709
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3999
bool isUnion() const
Definition Decl.h:4109
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3728
bool isVoidType() const
Definition TypeBase.h:9200
CXXRecordDecl * castAsCXXRecordDecl() const
Definition Type.h:36
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9498
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:885
bool isRecordType() const
Definition TypeBase.h:8942
QualType getType() const
Definition Decl.h:725
Represents a variable declaration or definition.
Definition Decl.h:934
#define not
Definition iso646.h:22
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit)
Return whether BaseInit initializes a base class that is dynamic, that is, one whose vtable pointer m...
bool isEmptyFieldForLayout(const ASTContext &Ctx, const FieldDecl *FD)
Return true iff the field is "empty", that is, either a zero-width bit-field or an isEmptyRecordForLa...
bool baseInitializerUsesThis(ASTContext &Ctx, const Expr *Init)
Check whether Init uses 'this' in a way which requires the vtable to be properly set.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
@ Ctor_Base
Base object ctor.
Definition ABI.h:26
@ Ctor_Complete
Complete object ctor.
Definition ABI.h:25
bool isa(CodeGen::Address addr)
Definition Address.h:330
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CXXDtorType
C++ destructor types.
Definition ABI.h:34
@ Dtor_Base
Base object dtor.
Definition ABI.h:37
@ Dtor_Complete
Complete object dtor.
Definition ABI.h:36
@ Dtor_Deleting
Deleting dtor.
Definition ABI.h:35
U cast(CodeGen::Address addr)
Definition Address.h:327
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
static bool addressSpace()
static bool useEHCleanupForArray()
static bool aggValueSlotGC()
static bool hiddenVisibility()
static bool runCleanupsScope()
static bool createInvariantGroup()
static bool isTrivialCtorOrDtor()
static bool pointerAuthentication()
static bool returnValueSlotFeatures()
static bool ctorMemcpyizer()
static bool generateDebugInfo()
static bool pointerFieldProtection()
static bool incrementProfileCounter()
clang::CharUnits storageOffset
The offset of the bitfield storage from the start of the record.
Similar to AddedStructorArgs, but only notes the number of additional arguments.
const clang::CXXRecordDecl * vtableClass
const clang::CXXRecordDecl * nearestVBase
cir::PointerType voidPtrTy
void* in address space 0