clang  16.0.0git
CGClass.cpp
Go to the documentation of this file.
1 //===--- CGClass.cpp - Emit LLVM Code for C++ classes -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This contains code dealing with C++ code generation of classes
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGBlocks.h"
14 #include "CGCXXABI.h"
15 #include "CGDebugInfo.h"
16 #include "CGRecordLayout.h"
17 #include "CodeGenFunction.h"
18 #include "TargetInfo.h"
19 #include "clang/AST/Attr.h"
21 #include "clang/AST/CharUnits.h"
22 #include "clang/AST/DeclTemplate.h"
24 #include "clang/AST/RecordLayout.h"
25 #include "clang/AST/StmtCXX.h"
29 #include "llvm/IR/Intrinsics.h"
30 #include "llvm/IR/Metadata.h"
31 #include "llvm/Transforms/Utils/SanitizerStats.h"
32 
33 using namespace clang;
34 using namespace CodeGen;
35 
36 /// Return the best known alignment for an unknown pointer to a
37 /// particular class.
39  if (!RD->hasDefinition())
40  return CharUnits::One(); // Hopefully won't be used anywhere.
41 
42  auto &layout = getContext().getASTRecordLayout(RD);
43 
44  // If the class is final, then we know that the pointer points to an
45  // object of that type and can use the full alignment.
46  if (RD->isEffectivelyFinal())
47  return layout.getAlignment();
48 
49  // Otherwise, we have to assume it could be a subclass.
50  return layout.getNonVirtualAlignment();
51 }
52 
53 /// Return the smallest possible amount of storage that might be allocated
54 /// starting from the beginning of an object of a particular class.
55 ///
56 /// This may be smaller than sizeof(RD) if RD has virtual base classes.
58  if (!RD->hasDefinition())
59  return CharUnits::One();
60 
61  auto &layout = getContext().getASTRecordLayout(RD);
62 
63  // If the class is final, then we know that the pointer points to an
64  // object of that type and can use the full alignment.
65  if (RD->isEffectivelyFinal())
66  return layout.getSize();
67 
68  // Otherwise, we have to assume it could be a subclass.
69  return std::max(layout.getNonVirtualSize(), CharUnits::One());
70 }
71 
72 /// Return the best known alignment for a pointer to a virtual base,
73 /// given the alignment of a pointer to the derived class.
75  const CXXRecordDecl *derivedClass,
76  const CXXRecordDecl *vbaseClass) {
77  // The basic idea here is that an underaligned derived pointer might
78  // indicate an underaligned base pointer.
79 
80  assert(vbaseClass->isCompleteDefinition());
81  auto &baseLayout = getContext().getASTRecordLayout(vbaseClass);
82  CharUnits expectedVBaseAlign = baseLayout.getNonVirtualAlignment();
83 
84  return getDynamicOffsetAlignment(actualDerivedAlign, derivedClass,
85  expectedVBaseAlign);
86 }
87 
90  const CXXRecordDecl *baseDecl,
91  CharUnits expectedTargetAlign) {
92  // If the base is an incomplete type (which is, alas, possible with
93  // member pointers), be pessimistic.
94  if (!baseDecl->isCompleteDefinition())
95  return std::min(actualBaseAlign, expectedTargetAlign);
96 
97  auto &baseLayout = getContext().getASTRecordLayout(baseDecl);
98  CharUnits expectedBaseAlign = baseLayout.getNonVirtualAlignment();
99 
100  // If the class is properly aligned, assume the target offset is, too.
101  //
102  // This actually isn't necessarily the right thing to do --- if the
103  // class is a complete object, but it's only properly aligned for a
104  // base subobject, then the alignments of things relative to it are
105  // probably off as well. (Note that this requires the alignment of
106  // the target to be greater than the NV alignment of the derived
107  // class.)
108  //
109  // However, our approach to this kind of under-alignment can only
110  // ever be best effort; after all, we're never going to propagate
111  // alignments through variables or parameters. Note, in particular,
112  // that constructing a polymorphic type in an address that's less
113  // than pointer-aligned will generally trap in the constructor,
114  // unless we someday add some sort of attribute to change the
115  // assumed alignment of 'this'. So our goal here is pretty much
116  // just to allow the user to explicitly say that a pointer is
117  // under-aligned and then safely access its fields and vtables.
118  if (actualBaseAlign >= expectedBaseAlign) {
119  return expectedTargetAlign;
120  }
121 
122  // Otherwise, we might be offset by an arbitrary multiple of the
123  // actual alignment. The correct adjustment is to take the min of
124  // the two alignments.
125  return std::min(actualBaseAlign, expectedTargetAlign);
126 }
127 
129  assert(CurFuncDecl && "loading 'this' without a func declaration?");
130  auto *MD = cast<CXXMethodDecl>(CurFuncDecl);
131 
132  // Lazily compute CXXThisAlignment.
133  if (CXXThisAlignment.isZero()) {
134  // Just use the best known alignment for the parent.
135  // TODO: if we're currently emitting a complete-object ctor/dtor,
136  // we can always use the complete-object alignment.
137  CXXThisAlignment = CGM.getClassPointerAlignment(MD->getParent());
138  }
139 
140  llvm::Type *Ty = ConvertType(MD->getThisType()->getPointeeType());
141  return Address(LoadCXXThis(), Ty, CXXThisAlignment);
142 }
143 
144 /// Emit the address of a field using a member data pointer.
145 ///
146 /// \param E Only used for emergency diagnostics
147 Address
149  llvm::Value *memberPtr,
150  const MemberPointerType *memberPtrType,
151  LValueBaseInfo *BaseInfo,
152  TBAAAccessInfo *TBAAInfo) {
153  // Ask the ABI to compute the actual address.
154  llvm::Value *ptr =
155  CGM.getCXXABI().EmitMemberDataPointerAddress(*this, E, base,
156  memberPtr, memberPtrType);
157 
158  QualType memberType = memberPtrType->getPointeeType();
159  CharUnits memberAlign =
160  CGM.getNaturalTypeAlignment(memberType, BaseInfo, TBAAInfo);
161  memberAlign =
163  memberPtrType->getClass()->getAsCXXRecordDecl(),
164  memberAlign);
165  return Address(ptr, ConvertTypeForMem(memberPtrType->getPointeeType()),
166  memberAlign);
167 }
168 
170  const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start,
173 
174  const ASTContext &Context = getContext();
175  const CXXRecordDecl *RD = DerivedClass;
176 
177  for (CastExpr::path_const_iterator I = Start; I != End; ++I) {
178  const CXXBaseSpecifier *Base = *I;
179  assert(!Base->isVirtual() && "Should not see virtual bases here!");
180 
181  // Get the layout.
182  const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
183 
184  const auto *BaseDecl =
185  cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
186 
187  // Add the offset.
188  Offset += Layout.getBaseClassOffset(BaseDecl);
189 
190  RD = BaseDecl;
191  }
192 
193  return Offset;
194 }
195 
196 llvm::Constant *
200  assert(PathBegin != PathEnd && "Base path should not be empty!");
201 
202  CharUnits Offset =
203  computeNonVirtualBaseClassOffset(ClassDecl, PathBegin, PathEnd);
204  if (Offset.isZero())
205  return nullptr;
206 
207  llvm::Type *PtrDiffTy =
208  Types.ConvertType(getContext().getPointerDiffType());
209 
210  return llvm::ConstantInt::get(PtrDiffTy, Offset.getQuantity());
211 }
212 
213 /// Gets the address of a direct base class within a complete object.
214 /// This should only be used for (1) non-virtual bases or (2) virtual bases
215 /// when the type is known to be complete (e.g. in complete destructors).
216 ///
217 /// The object pointed to by 'This' is assumed to be non-null.
218 Address
220  const CXXRecordDecl *Derived,
221  const CXXRecordDecl *Base,
222  bool BaseIsVirtual) {
223  // 'this' must be a pointer (in some address space) to Derived.
224  assert(This.getElementType() == ConvertType(Derived));
225 
226  // Compute the offset of the virtual base.
228  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Derived);
229  if (BaseIsVirtual)
230  Offset = Layout.getVBaseClassOffset(Base);
231  else
232  Offset = Layout.getBaseClassOffset(Base);
233 
234  // Shift and cast down to the base type.
235  // TODO: for complete types, this should be possible with a GEP.
236  Address V = This;
237  if (!Offset.isZero()) {
240  }
242 
243  return V;
244 }
245 
246 static Address
248  CharUnits nonVirtualOffset,
249  llvm::Value *virtualOffset,
250  const CXXRecordDecl *derivedClass,
251  const CXXRecordDecl *nearestVBase) {
252  // Assert that we have something to do.
253  assert(!nonVirtualOffset.isZero() || virtualOffset != nullptr);
254 
255  // Compute the offset from the static and dynamic components.
256  llvm::Value *baseOffset;
257  if (!nonVirtualOffset.isZero()) {
258  llvm::Type *OffsetType =
259  (CGF.CGM.getTarget().getCXXABI().isItaniumFamily() &&
261  ? CGF.Int32Ty
262  : CGF.PtrDiffTy;
263  baseOffset =
264  llvm::ConstantInt::get(OffsetType, nonVirtualOffset.getQuantity());
265  if (virtualOffset) {
266  baseOffset = CGF.Builder.CreateAdd(virtualOffset, baseOffset);
267  }
268  } else {
269  baseOffset = virtualOffset;
270  }
271 
272  // Apply the base offset.
273  llvm::Value *ptr = addr.getPointer();
274  unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
275  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
276  ptr = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ptr, baseOffset, "add.ptr");
277 
278  // If we have a virtual component, the alignment of the result will
279  // be relative only to the known alignment of that vbase.
280  CharUnits alignment;
281  if (virtualOffset) {
282  assert(nearestVBase && "virtual offset without vbase?");
283  alignment = CGF.CGM.getVBaseAlignment(addr.getAlignment(),
284  derivedClass, nearestVBase);
285  } else {
286  alignment = addr.getAlignment();
287  }
288  alignment = alignment.alignmentAtOffset(nonVirtualOffset);
289 
290  return Address(ptr, CGF.Int8Ty, alignment);
291 }
292 
294  Address Value, const CXXRecordDecl *Derived,
296  CastExpr::path_const_iterator PathEnd, bool NullCheckValue,
297  SourceLocation Loc) {
298  assert(PathBegin != PathEnd && "Base path should not be empty!");
299 
300  CastExpr::path_const_iterator Start = PathBegin;
301  const CXXRecordDecl *VBase = nullptr;
302 
303  // Sema has done some convenient canonicalization here: if the
304  // access path involved any virtual steps, the conversion path will
305  // *start* with a step down to the correct virtual base subobject,
306  // and hence will not require any further steps.
307  if ((*Start)->isVirtual()) {
308  VBase = cast<CXXRecordDecl>(
309  (*Start)->getType()->castAs<RecordType>()->getDecl());
310  ++Start;
311  }
312 
313  // Compute the static offset of the ultimate destination within its
314  // allocating subobject (the virtual base, if there is one, or else
315  // the "complete" object that we see).
317  VBase ? VBase : Derived, Start, PathEnd);
318 
319  // If there's a virtual step, we can sometimes "devirtualize" it.
320  // For now, that's limited to when the derived type is final.
321  // TODO: "devirtualize" this for accesses to known-complete objects.
322  if (VBase && Derived->hasAttr<FinalAttr>()) {
323  const ASTRecordLayout &layout = getContext().getASTRecordLayout(Derived);
324  CharUnits vBaseOffset = layout.getVBaseClassOffset(VBase);
325  NonVirtualOffset += vBaseOffset;
326  VBase = nullptr; // we no longer have a virtual step
327  }
328 
329  // Get the base pointer type.
330  llvm::Type *BaseValueTy = ConvertType((PathEnd[-1])->getType());
331  llvm::Type *BasePtrTy =
332  BaseValueTy->getPointerTo(Value.getType()->getPointerAddressSpace());
333 
334  QualType DerivedTy = getContext().getRecordType(Derived);
335  CharUnits DerivedAlign = CGM.getClassPointerAlignment(Derived);
336 
337  // If the static offset is zero and we don't have a virtual step,
338  // just do a bitcast; null checks are unnecessary.
339  if (NonVirtualOffset.isZero() && !VBase) {
340  if (sanitizePerformTypeCheck()) {
341  SanitizerSet SkippedChecks;
342  SkippedChecks.set(SanitizerKind::Null, !NullCheckValue);
343  EmitTypeCheck(TCK_Upcast, Loc, Value.getPointer(),
344  DerivedTy, DerivedAlign, SkippedChecks);
345  }
346  return Builder.CreateElementBitCast(Value, BaseValueTy);
347  }
348 
349  llvm::BasicBlock *origBB = nullptr;
350  llvm::BasicBlock *endBB = nullptr;
351 
352  // Skip over the offset (and the vtable load) if we're supposed to
353  // null-check the pointer.
354  if (NullCheckValue) {
355  origBB = Builder.GetInsertBlock();
356  llvm::BasicBlock *notNullBB = createBasicBlock("cast.notnull");
357  endBB = createBasicBlock("cast.end");
358 
359  llvm::Value *isNull = Builder.CreateIsNull(Value.getPointer());
360  Builder.CreateCondBr(isNull, endBB, notNullBB);
361  EmitBlock(notNullBB);
362  }
363 
364  if (sanitizePerformTypeCheck()) {
365  SanitizerSet SkippedChecks;
366  SkippedChecks.set(SanitizerKind::Null, true);
368  Value.getPointer(), DerivedTy, DerivedAlign, SkippedChecks);
369  }
370 
371  // Compute the virtual offset.
372  llvm::Value *VirtualOffset = nullptr;
373  if (VBase) {
374  VirtualOffset =
375  CGM.getCXXABI().GetVirtualBaseClassOffset(*this, Value, Derived, VBase);
376  }
377 
378  // Apply both offsets.
379  Value = ApplyNonVirtualAndVirtualOffset(*this, Value, NonVirtualOffset,
380  VirtualOffset, Derived, VBase);
381 
382  // Cast to the destination type.
383  Value = Builder.CreateElementBitCast(Value, BaseValueTy);
384 
385  // Build a phi if we needed a null check.
386  if (NullCheckValue) {
387  llvm::BasicBlock *notNullBB = Builder.GetInsertBlock();
388  Builder.CreateBr(endBB);
389  EmitBlock(endBB);
390 
391  llvm::PHINode *PHI = Builder.CreatePHI(BasePtrTy, 2, "cast.result");
392  PHI->addIncoming(Value.getPointer(), notNullBB);
393  PHI->addIncoming(llvm::Constant::getNullValue(BasePtrTy), origBB);
394  Value = Value.withPointer(PHI);
395  }
396 
397  return Value;
398 }
399 
400 Address
402  const CXXRecordDecl *Derived,
405  bool NullCheckValue) {
406  assert(PathBegin != PathEnd && "Base path should not be empty!");
407 
408  QualType DerivedTy =
409  getContext().getCanonicalType(getContext().getTagDeclType(Derived));
410  unsigned AddrSpace = BaseAddr.getAddressSpace();
411  llvm::Type *DerivedValueTy = ConvertType(DerivedTy);
412  llvm::Type *DerivedPtrTy = DerivedValueTy->getPointerTo(AddrSpace);
413 
414  llvm::Value *NonVirtualOffset =
415  CGM.GetNonVirtualBaseClassOffset(Derived, PathBegin, PathEnd);
416 
417  if (!NonVirtualOffset) {
418  // No offset, we can just cast back.
419  return Builder.CreateElementBitCast(BaseAddr, DerivedValueTy);
420  }
421 
422  llvm::BasicBlock *CastNull = nullptr;
423  llvm::BasicBlock *CastNotNull = nullptr;
424  llvm::BasicBlock *CastEnd = nullptr;
425 
426  if (NullCheckValue) {
427  CastNull = createBasicBlock("cast.null");
428  CastNotNull = createBasicBlock("cast.notnull");
429  CastEnd = createBasicBlock("cast.end");
430 
431  llvm::Value *IsNull = Builder.CreateIsNull(BaseAddr.getPointer());
432  Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
433  EmitBlock(CastNotNull);
434  }
435 
436  // Apply the offset.
437  llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy);
438  Value = Builder.CreateInBoundsGEP(
439  Int8Ty, Value, Builder.CreateNeg(NonVirtualOffset), "sub.ptr");
440 
441  // Just cast.
442  Value = Builder.CreateBitCast(Value, DerivedPtrTy);
443 
444  // Produce a PHI if we had a null-check.
445  if (NullCheckValue) {
446  Builder.CreateBr(CastEnd);
447  EmitBlock(CastNull);
448  Builder.CreateBr(CastEnd);
449  EmitBlock(CastEnd);
450 
451  llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2);
452  PHI->addIncoming(Value, CastNotNull);
453  PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
454  Value = PHI;
455  }
456 
457  return Address(Value, DerivedValueTy, CGM.getClassPointerAlignment(Derived));
458 }
459 
461  bool ForVirtualBase,
462  bool Delegating) {
463  if (!CGM.getCXXABI().NeedsVTTParameter(GD)) {
464  // This constructor/destructor does not need a VTT parameter.
465  return nullptr;
466  }
467 
468  const CXXRecordDecl *RD = cast<CXXMethodDecl>(CurCodeDecl)->getParent();
469  const CXXRecordDecl *Base = cast<CXXMethodDecl>(GD.getDecl())->getParent();
470 
471  uint64_t SubVTTIndex;
472 
473  if (Delegating) {
474  // If this is a delegating constructor call, just load the VTT.
475  return LoadCXXVTT();
476  } else if (RD == Base) {
477  // If the record matches the base, this is the complete ctor/dtor
478  // variant calling the base variant in a class with virtual bases.
479  assert(!CGM.getCXXABI().NeedsVTTParameter(CurGD) &&
480  "doing no-op VTT offset in base dtor/ctor?");
481  assert(!ForVirtualBase && "Can't have same class as virtual base!");
482  SubVTTIndex = 0;
483  } else {
484  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
485  CharUnits BaseOffset = ForVirtualBase ?
486  Layout.getVBaseClassOffset(Base) :
487  Layout.getBaseClassOffset(Base);
488 
489  SubVTTIndex =
490  CGM.getVTables().getSubVTTIndex(RD, BaseSubobject(Base, BaseOffset));
491  assert(SubVTTIndex != 0 && "Sub-VTT index must be greater than zero!");
492  }
493 
495  // A VTT parameter was passed to the constructor, use it.
496  llvm::Value *VTT = LoadCXXVTT();
497  return Builder.CreateConstInBoundsGEP1_64(VoidPtrTy, VTT, SubVTTIndex);
498  } else {
499  // We're the complete constructor, so get the VTT by name.
500  llvm::GlobalValue *VTT = CGM.getVTables().GetAddrOfVTT(RD);
501  return Builder.CreateConstInBoundsGEP2_64(
502  VTT->getValueType(), VTT, 0, SubVTTIndex);
503  }
504 }
505 
506 namespace {
507  /// Call the destructor for a direct base class.
508  struct CallBaseDtor final : EHScopeStack::Cleanup {
509  const CXXRecordDecl *BaseClass;
510  bool BaseIsVirtual;
511  CallBaseDtor(const CXXRecordDecl *Base, bool BaseIsVirtual)
512  : BaseClass(Base), BaseIsVirtual(BaseIsVirtual) {}
513 
514  void Emit(CodeGenFunction &CGF, Flags flags) override {
515  const CXXRecordDecl *DerivedClass =
516  cast<CXXMethodDecl>(CGF.CurCodeDecl)->getParent();
517 
518  const CXXDestructorDecl *D = BaseClass->getDestructor();
519  // We are already inside a destructor, so presumably the object being
520  // destroyed should have the expected type.
521  QualType ThisTy = D->getThisObjectType();
522  Address Addr =
524  DerivedClass, BaseClass,
525  BaseIsVirtual);
526  CGF.EmitCXXDestructorCall(D, Dtor_Base, BaseIsVirtual,
527  /*Delegating=*/false, Addr, ThisTy);
528  }
529  };
530 
531  /// A visitor which checks whether an initializer uses 'this' in a
532  /// way which requires the vtable to be properly set.
533  struct DynamicThisUseChecker : ConstEvaluatedExprVisitor<DynamicThisUseChecker> {
535 
536  bool UsesThis;
537 
538  DynamicThisUseChecker(const ASTContext &C) : super(C), UsesThis(false) {}
539 
540  // Black-list all explicit and implicit references to 'this'.
541  //
542  // Do we need to worry about external references to 'this' derived
543  // from arbitrary code? If so, then anything which runs arbitrary
544  // external code might potentially access the vtable.
545  void VisitCXXThisExpr(const CXXThisExpr *E) { UsesThis = true; }
546  };
547 } // end anonymous namespace
548 
549 static bool BaseInitializerUsesThis(ASTContext &C, const Expr *Init) {
550  DynamicThisUseChecker Checker(C);
551  Checker.Visit(Init);
552  return Checker.UsesThis;
553 }
554 
556  const CXXRecordDecl *ClassDecl,
557  CXXCtorInitializer *BaseInit) {
558  assert(BaseInit->isBaseInitializer() &&
559  "Must have base initializer!");
560 
561  Address ThisPtr = CGF.LoadCXXThisAddress();
562 
563  const Type *BaseType = BaseInit->getBaseClass();
564  const auto *BaseClassDecl =
565  cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl());
566 
567  bool isBaseVirtual = BaseInit->isBaseVirtual();
568 
569  // If the initializer for the base (other than the constructor
570  // itself) accesses 'this' in any way, we need to initialize the
571  // vtables.
572  if (BaseInitializerUsesThis(CGF.getContext(), BaseInit->getInit()))
573  CGF.InitializeVTablePointers(ClassDecl);
574 
575  // We can pretend to be a complete class because it only matters for
576  // virtual bases, and we only do virtual bases for complete ctors.
577  Address V =
578  CGF.GetAddressOfDirectBaseInCompleteClass(ThisPtr, ClassDecl,
579  BaseClassDecl,
580  isBaseVirtual);
581  AggValueSlot AggSlot =
583  V, Qualifiers(),
587  CGF.getOverlapForBaseInit(ClassDecl, BaseClassDecl, isBaseVirtual));
588 
589  CGF.EmitAggExpr(BaseInit->getInit(), AggSlot);
590 
591  if (CGF.CGM.getLangOpts().Exceptions &&
592  !BaseClassDecl->hasTrivialDestructor())
593  CGF.EHStack.pushCleanup<CallBaseDtor>(EHCleanup, BaseClassDecl,
594  isBaseVirtual);
595 }
596 
598  auto *CD = dyn_cast<CXXConstructorDecl>(D);
599  if (!(CD && CD->isCopyOrMoveConstructor()) &&
601  return false;
602 
603  // We can emit a memcpy for a trivial copy or move constructor/assignment.
604  if (D->isTrivial() && !D->getParent()->mayInsertExtraPadding())
605  return true;
606 
607  // We *must* emit a memcpy for a defaulted union copy or move op.
608  if (D->getParent()->isUnion() && D->isDefaulted())
609  return true;
610 
611  return false;
612 }
613 
615  CXXCtorInitializer *MemberInit,
616  LValue &LHS) {
617  FieldDecl *Field = MemberInit->getAnyMember();
618  if (MemberInit->isIndirectMemberInitializer()) {
619  // If we are initializing an anonymous union field, drill down to the field.
620  IndirectFieldDecl *IndirectField = MemberInit->getIndirectMember();
621  for (const auto *I : IndirectField->chain())
622  LHS = CGF.EmitLValueForFieldInitialization(LHS, cast<FieldDecl>(I));
623  } else {
624  LHS = CGF.EmitLValueForFieldInitialization(LHS, Field);
625  }
626 }
627 
629  const CXXRecordDecl *ClassDecl,
630  CXXCtorInitializer *MemberInit,
631  const CXXConstructorDecl *Constructor,
632  FunctionArgList &Args) {
633  ApplyDebugLocation Loc(CGF, MemberInit->getSourceLocation());
634  assert(MemberInit->isAnyMemberInitializer() &&
635  "Must have member initializer!");
636  assert(MemberInit->getInit() && "Must have initializer!");
637 
638  // non-static data member initializers.
639  FieldDecl *Field = MemberInit->getAnyMember();
640  QualType FieldType = Field->getType();
641 
642  llvm::Value *ThisPtr = CGF.LoadCXXThis();
643  QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl);
644  LValue LHS;
645 
646  // If a base constructor is being emitted, create an LValue that has the
647  // non-virtual alignment.
648  if (CGF.CurGD.getCtorType() == Ctor_Base)
649  LHS = CGF.MakeNaturalAlignPointeeAddrLValue(ThisPtr, RecordTy);
650  else
651  LHS = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy);
652 
653  EmitLValueForAnyFieldInitialization(CGF, MemberInit, LHS);
654 
655  // Special case: if we are in a copy or move constructor, and we are copying
656  // an array of PODs or classes with trivial copy constructors, ignore the
657  // AST and perform the copy we know is equivalent.
658  // FIXME: This is hacky at best... if we had a bit more explicit information
659  // in the AST, we could generalize it more easily.
660  const ConstantArrayType *Array
661  = CGF.getContext().getAsConstantArrayType(FieldType);
662  if (Array && Constructor->isDefaulted() &&
663  Constructor->isCopyOrMoveConstructor()) {
664  QualType BaseElementTy = CGF.getContext().getBaseElementType(Array);
665  CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(MemberInit->getInit());
666  if (BaseElementTy.isPODType(CGF.getContext()) ||
668  unsigned SrcArgIndex =
669  CGF.CGM.getCXXABI().getSrcArgforCopyCtor(Constructor, Args);
670  llvm::Value *SrcPtr
671  = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(Args[SrcArgIndex]));
672  LValue ThisRHSLV = CGF.MakeNaturalAlignAddrLValue(SrcPtr, RecordTy);
673  LValue Src = CGF.EmitLValueForFieldInitialization(ThisRHSLV, Field);
674 
675  // Copy the aggregate.
676  CGF.EmitAggregateCopy(LHS, Src, FieldType, CGF.getOverlapForFieldInit(Field),
677  LHS.isVolatileQualified());
678  // Ensure that we destroy the objects if an exception is thrown later in
679  // the constructor.
680  QualType::DestructionKind dtorKind = FieldType.isDestructedType();
681  if (CGF.needsEHCleanup(dtorKind))
682  CGF.pushEHDestroy(dtorKind, LHS.getAddress(CGF), FieldType);
683  return;
684  }
685  }
686 
687  CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit());
688 }
689 
691  Expr *Init) {
692  QualType FieldType = Field->getType();
693  switch (getEvaluationKind(FieldType)) {
694  case TEK_Scalar:
695  if (LHS.isSimple()) {
696  EmitExprAsInit(Init, Field, LHS, false);
697  } else {
698  RValue RHS = RValue::get(EmitScalarExpr(Init));
699  EmitStoreThroughLValue(RHS, LHS);
700  }
701  break;
702  case TEK_Complex:
703  EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true);
704  break;
705  case TEK_Aggregate: {
707  LHS, *this, AggValueSlot::IsDestructed,
710  // Checks are made by the code that calls constructor.
712  EmitAggExpr(Init, Slot);
713  break;
714  }
715  }
716 
717  // Ensure that we destroy this object if an exception is thrown
718  // later in the constructor.
719  QualType::DestructionKind dtorKind = FieldType.isDestructedType();
720  if (needsEHCleanup(dtorKind))
721  pushEHDestroy(dtorKind, LHS.getAddress(*this), FieldType);
722 }
723 
724 /// Checks whether the given constructor is a valid subject for the
725 /// complete-to-base constructor delegation optimization, i.e.
726 /// emitting the complete constructor as a simple call to the base
727 /// constructor.
729  const CXXConstructorDecl *Ctor) {
730 
731  // Currently we disable the optimization for classes with virtual
732  // bases because (1) the addresses of parameter variables need to be
733  // consistent across all initializers but (2) the delegate function
734  // call necessarily creates a second copy of the parameter variable.
735  //
736  // The limiting example (purely theoretical AFAIK):
737  // struct A { A(int &c) { c++; } };
738  // struct B : virtual A {
739  // B(int count) : A(count) { printf("%d\n", count); }
740  // };
741  // ...although even this example could in principle be emitted as a
742  // delegation since the address of the parameter doesn't escape.
743  if (Ctor->getParent()->getNumVBases()) {
744  // TODO: white-list trivial vbase initializers. This case wouldn't
745  // be subject to the restrictions below.
746 
747  // TODO: white-list cases where:
748  // - there are no non-reference parameters to the constructor
749  // - the initializers don't access any non-reference parameters
750  // - the initializers don't take the address of non-reference
751  // parameters
752  // - etc.
753  // If we ever add any of the above cases, remember that:
754  // - function-try-blocks will always exclude this optimization
755  // - we need to perform the constructor prologue and cleanup in
756  // EmitConstructorBody.
757 
758  return false;
759  }
760 
761  // We also disable the optimization for variadic functions because
762  // it's impossible to "re-pass" varargs.
763  if (Ctor->getType()->castAs<FunctionProtoType>()->isVariadic())
764  return false;
765 
766  // FIXME: Decide if we can do a delegation of a delegating constructor.
767  if (Ctor->isDelegatingConstructor())
768  return false;
769 
770  return true;
771 }
772 
773 // Emit code in ctor (Prologue==true) or dtor (Prologue==false)
774 // to poison the extra field paddings inserted under
775 // -fsanitize-address-field-padding=1|2.
777  ASTContext &Context = getContext();
778  const CXXRecordDecl *ClassDecl =
779  Prologue ? cast<CXXConstructorDecl>(CurGD.getDecl())->getParent()
780  : cast<CXXDestructorDecl>(CurGD.getDecl())->getParent();
781  if (!ClassDecl->mayInsertExtraPadding()) return;
782 
783  struct SizeAndOffset {
784  uint64_t Size;
786  };
787 
788  unsigned PtrSize = CGM.getDataLayout().getPointerSizeInBits();
789  const ASTRecordLayout &Info = Context.getASTRecordLayout(ClassDecl);
790 
791  // Populate sizes and offsets of fields.
793  for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i)
794  SSV[i].Offset =
796 
797  size_t NumFields = 0;
798  for (const auto *Field : ClassDecl->fields()) {
799  const FieldDecl *D = Field;
800  auto FieldInfo = Context.getTypeInfoInChars(D->getType());
801  CharUnits FieldSize = FieldInfo.Width;
802  assert(NumFields < SSV.size());
803  SSV[NumFields].Size = D->isBitField() ? 0 : FieldSize.getQuantity();
804  NumFields++;
805  }
806  assert(NumFields == SSV.size());
807  if (SSV.size() <= 1) return;
808 
809  // We will insert calls to __asan_* run-time functions.
810  // LLVM AddressSanitizer pass may decide to inline them later.
811  llvm::Type *Args[2] = {IntPtrTy, IntPtrTy};
812  llvm::FunctionType *FTy =
813  llvm::FunctionType::get(CGM.VoidTy, Args, false);
814  llvm::FunctionCallee F = CGM.CreateRuntimeFunction(
815  FTy, Prologue ? "__asan_poison_intra_object_redzone"
816  : "__asan_unpoison_intra_object_redzone");
817 
818  llvm::Value *ThisPtr = LoadCXXThis();
819  ThisPtr = Builder.CreatePtrToInt(ThisPtr, IntPtrTy);
820  uint64_t TypeSize = Info.getNonVirtualSize().getQuantity();
821  // For each field check if it has sufficient padding,
822  // if so (un)poison it with a call.
823  for (size_t i = 0; i < SSV.size(); i++) {
824  uint64_t AsanAlignment = 8;
825  uint64_t NextField = i == SSV.size() - 1 ? TypeSize : SSV[i + 1].Offset;
826  uint64_t PoisonSize = NextField - SSV[i].Offset - SSV[i].Size;
827  uint64_t EndOffset = SSV[i].Offset + SSV[i].Size;
828  if (PoisonSize < AsanAlignment || !SSV[i].Size ||
829  (NextField % AsanAlignment) != 0)
830  continue;
831  Builder.CreateCall(
832  F, {Builder.CreateAdd(ThisPtr, Builder.getIntN(PtrSize, EndOffset)),
833  Builder.getIntN(PtrSize, PoisonSize)});
834  }
835 }
836 
837 /// EmitConstructorBody - Emits the body of the current constructor.
840  const CXXConstructorDecl *Ctor = cast<CXXConstructorDecl>(CurGD.getDecl());
841  CXXCtorType CtorType = CurGD.getCtorType();
842 
844  CtorType == Ctor_Complete) &&
845  "can only generate complete ctor for this ABI");
846 
847  // Before we go any further, try the complete->base constructor
848  // delegation optimization.
849  if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor) &&
851  EmitDelegateCXXConstructorCall(Ctor, Ctor_Base, Args, Ctor->getEndLoc());
852  return;
853  }
854 
855  const FunctionDecl *Definition = nullptr;
856  Stmt *Body = Ctor->getBody(Definition);
857  assert(Definition == Ctor && "emitting wrong constructor body");
858 
859  // Enter the function-try-block before the constructor prologue if
860  // applicable.
861  bool IsTryBody = (Body && isa<CXXTryStmt>(Body));
862  if (IsTryBody)
863  EnterCXXTryStmt(*cast<CXXTryStmt>(Body), true);
864 
866 
867  RunCleanupsScope RunCleanups(*this);
868 
869  // TODO: in restricted cases, we can emit the vbase initializers of
870  // a complete ctor and then delegate to the base ctor.
871 
872  // Emit the constructor prologue, i.e. the base and member
873  // initializers.
874  EmitCtorPrologue(Ctor, CtorType, Args);
875 
876  // Emit the body of the statement.
877  if (IsTryBody)
878  EmitStmt(cast<CXXTryStmt>(Body)->getTryBlock());
879  else if (Body)
880  EmitStmt(Body);
881 
882  // Emit any cleanup blocks associated with the member or base
883  // initializers, which includes (along the exceptional path) the
884  // destructors for those members and bases that were fully
885  // constructed.
886  RunCleanups.ForceCleanup();
887 
888  if (IsTryBody)
889  ExitCXXTryStmt(*cast<CXXTryStmt>(Body), true);
890 }
891 
892 namespace {
893  /// RAII object to indicate that codegen is copying the value representation
894  /// instead of the object representation. Useful when copying a struct or
895  /// class which has uninitialized members and we're only performing
896  /// lvalue-to-rvalue conversion on the object but not its members.
897  class CopyingValueRepresentation {
898  public:
899  explicit CopyingValueRepresentation(CodeGenFunction &CGF)
900  : CGF(CGF), OldSanOpts(CGF.SanOpts) {
901  CGF.SanOpts.set(SanitizerKind::Bool, false);
902  CGF.SanOpts.set(SanitizerKind::Enum, false);
903  }
904  ~CopyingValueRepresentation() {
905  CGF.SanOpts = OldSanOpts;
906  }
907  private:
908  CodeGenFunction &CGF;
909  SanitizerSet OldSanOpts;
910  };
911 } // end anonymous namespace
912 
913 namespace {
914  class FieldMemcpyizer {
915  public:
916  FieldMemcpyizer(CodeGenFunction &CGF, const CXXRecordDecl *ClassDecl,
917  const VarDecl *SrcRec)
918  : CGF(CGF), ClassDecl(ClassDecl), SrcRec(SrcRec),
919  RecLayout(CGF.getContext().getASTRecordLayout(ClassDecl)),
920  FirstField(nullptr), LastField(nullptr), FirstFieldOffset(0),
921  LastFieldOffset(0), LastAddedFieldIndex(0) {}
922 
923  bool isMemcpyableField(FieldDecl *F) const {
924  // Never memcpy fields when we are adding poisoned paddings.
925  if (CGF.getContext().getLangOpts().SanitizeAddressFieldPadding)
926  return false;
927  Qualifiers Qual = F->getType().getQualifiers();
928  if (Qual.hasVolatile() || Qual.hasObjCLifetime())
929  return false;
930  return true;
931  }
932 
933  void addMemcpyableField(FieldDecl *F) {
934  if (F->isZeroSize(CGF.getContext()))
935  return;
936  if (!FirstField)
937  addInitialField(F);
938  else
939  addNextField(F);
940  }
941 
942  CharUnits getMemcpySize(uint64_t FirstByteOffset) const {
943  ASTContext &Ctx = CGF.getContext();
944  unsigned LastFieldSize =
945  LastField->isBitField()
946  ? LastField->getBitWidthValue(Ctx)
947  : Ctx.toBits(
948  Ctx.getTypeInfoDataSizeInChars(LastField->getType()).Width);
949  uint64_t MemcpySizeBits = LastFieldOffset + LastFieldSize -
950  FirstByteOffset + Ctx.getCharWidth() - 1;
951  CharUnits MemcpySize = Ctx.toCharUnitsFromBits(MemcpySizeBits);
952  return MemcpySize;
953  }
954 
955  void emitMemcpy() {
956  // Give the subclass a chance to bail out if it feels the memcpy isn't
957  // worth it (e.g. Hasn't aggregated enough data).
958  if (!FirstField) {
959  return;
960  }
961 
962  uint64_t FirstByteOffset;
963  if (FirstField->isBitField()) {
964  const CGRecordLayout &RL =
965  CGF.getTypes().getCGRecordLayout(FirstField->getParent());
966  const CGBitFieldInfo &BFInfo = RL.getBitFieldInfo(FirstField);
967  // FirstFieldOffset is not appropriate for bitfields,
968  // we need to use the storage offset instead.
969  FirstByteOffset = CGF.getContext().toBits(BFInfo.StorageOffset);
970  } else {
971  FirstByteOffset = FirstFieldOffset;
972  }
973 
974  CharUnits MemcpySize = getMemcpySize(FirstByteOffset);
975  QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl);
976  Address ThisPtr = CGF.LoadCXXThisAddress();
977  LValue DestLV = CGF.MakeAddrLValue(ThisPtr, RecordTy);
978  LValue Dest = CGF.EmitLValueForFieldInitialization(DestLV, FirstField);
979  llvm::Value *SrcPtr = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(SrcRec));
980  LValue SrcLV = CGF.MakeNaturalAlignAddrLValue(SrcPtr, RecordTy);
981  LValue Src = CGF.EmitLValueForFieldInitialization(SrcLV, FirstField);
982 
983  emitMemcpyIR(
984  Dest.isBitField() ? Dest.getBitFieldAddress() : Dest.getAddress(CGF),
985  Src.isBitField() ? Src.getBitFieldAddress() : Src.getAddress(CGF),
986  MemcpySize);
987  reset();
988  }
989 
990  void reset() {
991  FirstField = nullptr;
992  }
993 
994  protected:
995  CodeGenFunction &CGF;
996  const CXXRecordDecl *ClassDecl;
997 
998  private:
999  void emitMemcpyIR(Address DestPtr, Address SrcPtr, CharUnits Size) {
1000  DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty);
1001  SrcPtr = CGF.Builder.CreateElementBitCast(SrcPtr, CGF.Int8Ty);
1002  CGF.Builder.CreateMemCpy(DestPtr, SrcPtr, Size.getQuantity());
1003  }
1004 
1005  void addInitialField(FieldDecl *F) {
1006  FirstField = F;
1007  LastField = F;
1008  FirstFieldOffset = RecLayout.getFieldOffset(F->getFieldIndex());
1009  LastFieldOffset = FirstFieldOffset;
1010  LastAddedFieldIndex = F->getFieldIndex();
1011  }
1012 
1013  void addNextField(FieldDecl *F) {
1014  // For the most part, the following invariant will hold:
1015  // F->getFieldIndex() == LastAddedFieldIndex + 1
1016  // The one exception is that Sema won't add a copy-initializer for an
1017  // unnamed bitfield, which will show up here as a gap in the sequence.
1018  assert(F->getFieldIndex() >= LastAddedFieldIndex + 1 &&
1019  "Cannot aggregate fields out of order.");
1020  LastAddedFieldIndex = F->getFieldIndex();
1021 
1022  // The 'first' and 'last' fields are chosen by offset, rather than field
1023  // index. This allows the code to support bitfields, as well as regular
1024  // fields.
1025  uint64_t FOffset = RecLayout.getFieldOffset(F->getFieldIndex());
1026  if (FOffset < FirstFieldOffset) {
1027  FirstField = F;
1028  FirstFieldOffset = FOffset;
1029  } else if (FOffset >= LastFieldOffset) {
1030  LastField = F;
1031  LastFieldOffset = FOffset;
1032  }
1033  }
1034 
1035  const VarDecl *SrcRec;
1036  const ASTRecordLayout &RecLayout;
1037  FieldDecl *FirstField;
1038  FieldDecl *LastField;
1039  uint64_t FirstFieldOffset, LastFieldOffset;
1040  unsigned LastAddedFieldIndex;
1041  };
1042 
1043  class ConstructorMemcpyizer : public FieldMemcpyizer {
1044  private:
1045  /// Get source argument for copy constructor. Returns null if not a copy
1046  /// constructor.
1047  static const VarDecl *getTrivialCopySource(CodeGenFunction &CGF,
1048  const CXXConstructorDecl *CD,
1049  FunctionArgList &Args) {
1050  if (CD->isCopyOrMoveConstructor() && CD->isDefaulted())
1051  return Args[CGF.CGM.getCXXABI().getSrcArgforCopyCtor(CD, Args)];
1052  return nullptr;
1053  }
1054 
1055  // Returns true if a CXXCtorInitializer represents a member initialization
1056  // that can be rolled into a memcpy.
1057  bool isMemberInitMemcpyable(CXXCtorInitializer *MemberInit) const {
1058  if (!MemcpyableCtor)
1059  return false;
1060  FieldDecl *Field = MemberInit->getMember();
1061  assert(Field && "No field for member init.");
1062  QualType FieldType = Field->getType();
1063  CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(MemberInit->getInit());
1064 
1065  // Bail out on non-memcpyable, not-trivially-copyable members.
1066  if (!(CE && isMemcpyEquivalentSpecialMember(CE->getConstructor())) &&
1067  !(FieldType.isTriviallyCopyableType(CGF.getContext()) ||
1068  FieldType->isReferenceType()))
1069  return false;
1070 
1071  // Bail out on volatile fields.
1072  if (!isMemcpyableField(Field))
1073  return false;
1074 
1075  // Otherwise we're good.
1076  return true;
1077  }
1078 
1079  public:
1080  ConstructorMemcpyizer(CodeGenFunction &CGF, const CXXConstructorDecl *CD,
1081  FunctionArgList &Args)
1082  : FieldMemcpyizer(CGF, CD->getParent(), getTrivialCopySource(CGF, CD, Args)),
1083  ConstructorDecl(CD),
1084  MemcpyableCtor(CD->isDefaulted() &&
1085  CD->isCopyOrMoveConstructor() &&
1086  CGF.getLangOpts().getGC() == LangOptions::NonGC),
1087  Args(Args) { }
1088 
1089  void addMemberInitializer(CXXCtorInitializer *MemberInit) {
1090  if (isMemberInitMemcpyable(MemberInit)) {
1091  AggregatedInits.push_back(MemberInit);
1092  addMemcpyableField(MemberInit->getMember());
1093  } else {
1094  emitAggregatedInits();
1095  EmitMemberInitializer(CGF, ConstructorDecl->getParent(), MemberInit,
1096  ConstructorDecl, Args);
1097  }
1098  }
1099 
1100  void emitAggregatedInits() {
1101  if (AggregatedInits.size() <= 1) {
1102  // This memcpy is too small to be worthwhile. Fall back on default
1103  // codegen.
1104  if (!AggregatedInits.empty()) {
1105  CopyingValueRepresentation CVR(CGF);
1106  EmitMemberInitializer(CGF, ConstructorDecl->getParent(),
1107  AggregatedInits[0], ConstructorDecl, Args);
1108  AggregatedInits.clear();
1109  }
1110  reset();
1111  return;
1112  }
1113 
1114  pushEHDestructors();
1115  emitMemcpy();
1116  AggregatedInits.clear();
1117  }
1118 
1119  void pushEHDestructors() {
1120  Address ThisPtr = CGF.LoadCXXThisAddress();
1121  QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl);
1122  LValue LHS = CGF.MakeAddrLValue(ThisPtr, RecordTy);
1123 
1124  for (unsigned i = 0; i < AggregatedInits.size(); ++i) {
1125  CXXCtorInitializer *MemberInit = AggregatedInits[i];
1126  QualType FieldType = MemberInit->getAnyMember()->getType();
1127  QualType::DestructionKind dtorKind = FieldType.isDestructedType();
1128  if (!CGF.needsEHCleanup(dtorKind))
1129  continue;
1130  LValue FieldLHS = LHS;
1131  EmitLValueForAnyFieldInitialization(CGF, MemberInit, FieldLHS);
1132  CGF.pushEHDestroy(dtorKind, FieldLHS.getAddress(CGF), FieldType);
1133  }
1134  }
1135 
1136  void finish() {
1137  emitAggregatedInits();
1138  }
1139 
1140  private:
1141  const CXXConstructorDecl *ConstructorDecl;
1142  bool MemcpyableCtor;
1143  FunctionArgList &Args;
1144  SmallVector<CXXCtorInitializer*, 16> AggregatedInits;
1145  };
1146 
1147  class AssignmentMemcpyizer : public FieldMemcpyizer {
1148  private:
1149  // Returns the memcpyable field copied by the given statement, if one
1150  // exists. Otherwise returns null.
1151  FieldDecl *getMemcpyableField(Stmt *S) {
1152  if (!AssignmentsMemcpyable)
1153  return nullptr;
1154  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(S)) {
1155  // Recognise trivial assignments.
1156  if (BO->getOpcode() != BO_Assign)
1157  return nullptr;
1158  MemberExpr *ME = dyn_cast<MemberExpr>(BO->getLHS());
1159  if (!ME)
1160  return nullptr;
1161  FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
1162  if (!Field || !isMemcpyableField(Field))
1163  return nullptr;
1164  Stmt *RHS = BO->getRHS();
1165  if (ImplicitCastExpr *EC = dyn_cast<ImplicitCastExpr>(RHS))
1166  RHS = EC->getSubExpr();
1167  if (!RHS)
1168  return nullptr;
1169  if (MemberExpr *ME2 = dyn_cast<MemberExpr>(RHS)) {
1170  if (ME2->getMemberDecl() == Field)
1171  return Field;
1172  }
1173  return nullptr;
1174  } else if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(S)) {
1175  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MCE->getCalleeDecl());
1176  if (!(MD && isMemcpyEquivalentSpecialMember(MD)))
1177  return nullptr;
1178  MemberExpr *IOA = dyn_cast<MemberExpr>(MCE->getImplicitObjectArgument());
1179  if (!IOA)
1180  return nullptr;
1181  FieldDecl *Field = dyn_cast<FieldDecl>(IOA->getMemberDecl());
1182  if (!Field || !isMemcpyableField(Field))
1183  return nullptr;
1184  MemberExpr *Arg0 = dyn_cast<MemberExpr>(MCE->getArg(0));
1185  if (!Arg0 || Field != dyn_cast<FieldDecl>(Arg0->getMemberDecl()))
1186  return nullptr;
1187  return Field;
1188  } else if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
1189  FunctionDecl *FD = dyn_cast<FunctionDecl>(CE->getCalleeDecl());
1190  if (!FD || FD->getBuiltinID() != Builtin::BI__builtin_memcpy)
1191  return nullptr;
1192  Expr *DstPtr = CE->getArg(0);
1193  if (ImplicitCastExpr *DC = dyn_cast<ImplicitCastExpr>(DstPtr))
1194  DstPtr = DC->getSubExpr();
1195  UnaryOperator *DUO = dyn_cast<UnaryOperator>(DstPtr);
1196  if (!DUO || DUO->getOpcode() != UO_AddrOf)
1197  return nullptr;
1198  MemberExpr *ME = dyn_cast<MemberExpr>(DUO->getSubExpr());
1199  if (!ME)
1200  return nullptr;
1201  FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
1202  if (!Field || !isMemcpyableField(Field))
1203  return nullptr;
1204  Expr *SrcPtr = CE->getArg(1);
1205  if (ImplicitCastExpr *SC = dyn_cast<ImplicitCastExpr>(SrcPtr))
1206  SrcPtr = SC->getSubExpr();
1207  UnaryOperator *SUO = dyn_cast<UnaryOperator>(SrcPtr);
1208  if (!SUO || SUO->getOpcode() != UO_AddrOf)
1209  return nullptr;
1210  MemberExpr *ME2 = dyn_cast<MemberExpr>(SUO->getSubExpr());
1211  if (!ME2 || Field != dyn_cast<FieldDecl>(ME2->getMemberDecl()))
1212  return nullptr;
1213  return Field;
1214  }
1215 
1216  return nullptr;
1217  }
1218 
1219  bool AssignmentsMemcpyable;
1220  SmallVector<Stmt*, 16> AggregatedStmts;
1221 
1222  public:
1223  AssignmentMemcpyizer(CodeGenFunction &CGF, const CXXMethodDecl *AD,
1224  FunctionArgList &Args)
1225  : FieldMemcpyizer(CGF, AD->getParent(), Args[Args.size() - 1]),
1226  AssignmentsMemcpyable(CGF.getLangOpts().getGC() == LangOptions::NonGC) {
1227  assert(Args.size() == 2);
1228  }
1229 
1230  void emitAssignment(Stmt *S) {
1231  FieldDecl *F = getMemcpyableField(S);
1232  if (F) {
1233  addMemcpyableField(F);
1234  AggregatedStmts.push_back(S);
1235  } else {
1236  emitAggregatedStmts();
1237  CGF.EmitStmt(S);
1238  }
1239  }
1240 
1241  void emitAggregatedStmts() {
1242  if (AggregatedStmts.size() <= 1) {
1243  if (!AggregatedStmts.empty()) {
1244  CopyingValueRepresentation CVR(CGF);
1245  CGF.EmitStmt(AggregatedStmts[0]);
1246  }
1247  reset();
1248  }
1249 
1250  emitMemcpy();
1251  AggregatedStmts.clear();
1252  }
1253 
1254  void finish() {
1255  emitAggregatedStmts();
1256  }
1257  };
1258 } // end anonymous namespace
1259 
1260 static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit) {
1261  const Type *BaseType = BaseInit->getBaseClass();
1262  const auto *BaseClassDecl =
1263  cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl());
1264  return BaseClassDecl->isDynamicClass();
1265 }
1266 
1267 /// EmitCtorPrologue - This routine generates necessary code to initialize
1268 /// base classes and non-static data members belonging to this constructor.
1270  CXXCtorType CtorType,
1271  FunctionArgList &Args) {
1272  if (CD->isDelegatingConstructor())
1273  return EmitDelegatingCXXConstructorCall(CD, Args);
1274 
1275  const CXXRecordDecl *ClassDecl = CD->getParent();
1276 
1278  E = CD->init_end();
1279 
1280  // Virtual base initializers first, if any. They aren't needed if:
1281  // - This is a base ctor variant
1282  // - There are no vbases
1283  // - The class is abstract, so a complete object of it cannot be constructed
1284  //
1285  // The check for an abstract class is necessary because sema may not have
1286  // marked virtual base destructors referenced.
1287  bool ConstructVBases = CtorType != Ctor_Base &&
1288  ClassDecl->getNumVBases() != 0 &&
1289  !ClassDecl->isAbstract();
1290 
1291  // In the Microsoft C++ ABI, there are no constructor variants. Instead, the
1292  // constructor of a class with virtual bases takes an additional parameter to
1293  // conditionally construct the virtual bases. Emit that check here.
1294  llvm::BasicBlock *BaseCtorContinueBB = nullptr;
1295  if (ConstructVBases &&
1297  BaseCtorContinueBB =
1298  CGM.getCXXABI().EmitCtorCompleteObjectHandler(*this, ClassDecl);
1299  assert(BaseCtorContinueBB);
1300  }
1301 
1302  llvm::Value *const OldThis = CXXThisValue;
1303  for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
1304  if (!ConstructVBases)
1305  continue;
1306  if (CGM.getCodeGenOpts().StrictVTablePointers &&
1307  CGM.getCodeGenOpts().OptimizationLevel > 0 &&
1310  EmitBaseInitializer(*this, ClassDecl, *B);
1311  }
1312 
1313  if (BaseCtorContinueBB) {
1314  // Complete object handler should continue to the remaining initializers.
1315  Builder.CreateBr(BaseCtorContinueBB);
1316  EmitBlock(BaseCtorContinueBB);
1317  }
1318 
1319  // Then, non-virtual base initializers.
1320  for (; B != E && (*B)->isBaseInitializer(); B++) {
1321  assert(!(*B)->isBaseVirtual());
1322 
1323  if (CGM.getCodeGenOpts().StrictVTablePointers &&
1324  CGM.getCodeGenOpts().OptimizationLevel > 0 &&
1327  EmitBaseInitializer(*this, ClassDecl, *B);
1328  }
1329 
1330  CXXThisValue = OldThis;
1331 
1332  InitializeVTablePointers(ClassDecl);
1333 
1334  // And finally, initialize class members.
1336  ConstructorMemcpyizer CM(*this, CD, Args);
1337  for (; B != E; B++) {
1338  CXXCtorInitializer *Member = (*B);
1339  assert(!Member->isBaseInitializer());
1340  assert(Member->isAnyMemberInitializer() &&
1341  "Delegating initializer on non-delegating constructor");
1342  CM.addMemberInitializer(Member);
1343  }
1344  CM.finish();
1345 }
1346 
1347 static bool
1348 FieldHasTrivialDestructorBody(ASTContext &Context, const FieldDecl *Field);
1349 
1350 static bool
1352  const CXXRecordDecl *BaseClassDecl,
1353  const CXXRecordDecl *MostDerivedClassDecl)
1354 {
1355  // If the destructor is trivial we don't have to check anything else.
1356  if (BaseClassDecl->hasTrivialDestructor())
1357  return true;
1358 
1359  if (!BaseClassDecl->getDestructor()->hasTrivialBody())
1360  return false;
1361 
1362  // Check fields.
1363  for (const auto *Field : BaseClassDecl->fields())
1364  if (!FieldHasTrivialDestructorBody(Context, Field))
1365  return false;
1366 
1367  // Check non-virtual bases.
1368  for (const auto &I : BaseClassDecl->bases()) {
1369  if (I.isVirtual())
1370  continue;
1371 
1372  const CXXRecordDecl *NonVirtualBase =
1373  cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
1374  if (!HasTrivialDestructorBody(Context, NonVirtualBase,
1375  MostDerivedClassDecl))
1376  return false;
1377  }
1378 
1379  if (BaseClassDecl == MostDerivedClassDecl) {
1380  // Check virtual bases.
1381  for (const auto &I : BaseClassDecl->vbases()) {
1382  const CXXRecordDecl *VirtualBase =
1383  cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
1384  if (!HasTrivialDestructorBody(Context, VirtualBase,
1385  MostDerivedClassDecl))
1386  return false;
1387  }
1388  }
1389 
1390  return true;
1391 }
1392 
1393 static bool
1395  const FieldDecl *Field)
1396 {
1397  QualType FieldBaseElementType = Context.getBaseElementType(Field->getType());
1398 
1399  const RecordType *RT = FieldBaseElementType->getAs<RecordType>();
1400  if (!RT)
1401  return true;
1402 
1403  CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
1404 
1405  // The destructor for an implicit anonymous union member is never invoked.
1406  if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
1407  return false;
1408 
1409  return HasTrivialDestructorBody(Context, FieldClassDecl, FieldClassDecl);
1410 }
1411 
1412 /// CanSkipVTablePointerInitialization - Check whether we need to initialize
1413 /// any vtable pointers before calling this destructor.
1415  const CXXDestructorDecl *Dtor) {
1416  const CXXRecordDecl *ClassDecl = Dtor->getParent();
1417  if (!ClassDecl->isDynamicClass())
1418  return true;
1419 
1420  // For a final class, the vtable pointer is known to already point to the
1421  // class's vtable.
1422  if (ClassDecl->isEffectivelyFinal())
1423  return true;
1424 
1425  if (!Dtor->hasTrivialBody())
1426  return false;
1427 
1428  // Check the fields.
1429  for (const auto *Field : ClassDecl->fields())
1430  if (!FieldHasTrivialDestructorBody(CGF.getContext(), Field))
1431  return false;
1432 
1433  return true;
1434 }
1435 
1436 /// EmitDestructorBody - Emits the body of the current destructor.
1438  const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CurGD.getDecl());
1439  CXXDtorType DtorType = CurGD.getDtorType();
1440 
1441  // For an abstract class, non-base destructors are never used (and can't
1442  // be emitted in general, because vbase dtors may not have been validated
1443  // by Sema), but the Itanium ABI doesn't make them optional and Clang may
1444  // in fact emit references to them from other compilations, so emit them
1445  // as functions containing a trap instruction.
1446  if (DtorType != Dtor_Base && Dtor->getParent()->isAbstract()) {
1447  llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap);
1448  TrapCall->setDoesNotReturn();
1449  TrapCall->setDoesNotThrow();
1450  Builder.CreateUnreachable();
1451  Builder.ClearInsertionPoint();
1452  return;
1453  }
1454 
1455  Stmt *Body = Dtor->getBody();
1456  if (Body)
1458 
1459  // The call to operator delete in a deleting destructor happens
1460  // outside of the function-try-block, which means it's always
1461  // possible to delegate the destructor body to the complete
1462  // destructor. Do so.
1463  if (DtorType == Dtor_Deleting) {
1464  RunCleanupsScope DtorEpilogue(*this);
1466  if (HaveInsertPoint()) {
1467  QualType ThisTy = Dtor->getThisObjectType();
1468  EmitCXXDestructorCall(Dtor, Dtor_Complete, /*ForVirtualBase=*/false,
1469  /*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
1470  }
1471  return;
1472  }
1473 
1474  // If the body is a function-try-block, enter the try before
1475  // anything else.
1476  bool isTryBody = (Body && isa<CXXTryStmt>(Body));
1477  if (isTryBody)
1478  EnterCXXTryStmt(*cast<CXXTryStmt>(Body), true);
1480 
1481  // Enter the epilogue cleanups.
1482  RunCleanupsScope DtorEpilogue(*this);
1483 
1484  // If this is the complete variant, just invoke the base variant;
1485  // the epilogue will destruct the virtual bases. But we can't do
1486  // this optimization if the body is a function-try-block, because
1487  // we'd introduce *two* handler blocks. In the Microsoft ABI, we
1488  // always delegate because we might not have a definition in this TU.
1489  switch (DtorType) {
1490  case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
1491  case Dtor_Deleting: llvm_unreachable("already handled deleting case");
1492 
1493  case Dtor_Complete:
1494  assert((Body || getTarget().getCXXABI().isMicrosoft()) &&
1495  "can't emit a dtor without a body for non-Microsoft ABIs");
1496 
1497  // Enter the cleanup scopes for virtual bases.
1499 
1500  if (!isTryBody) {
1501  QualType ThisTy = Dtor->getThisObjectType();
1502  EmitCXXDestructorCall(Dtor, Dtor_Base, /*ForVirtualBase=*/false,
1503  /*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
1504  break;
1505  }
1506 
1507  // Fallthrough: act like we're in the base variant.
1508  [[fallthrough]];
1509 
1510  case Dtor_Base:
1511  assert(Body);
1512 
1513  // Enter the cleanup scopes for fields and non-virtual bases.
1515 
1516  // Initialize the vtable pointers before entering the body.
1517  if (!CanSkipVTablePointerInitialization(*this, Dtor)) {
1518  // Insert the llvm.launder.invariant.group intrinsic before initializing
1519  // the vptrs to cancel any previous assumptions we might have made.
1520  if (CGM.getCodeGenOpts().StrictVTablePointers &&
1521  CGM.getCodeGenOpts().OptimizationLevel > 0)
1524  }
1525 
1526  if (isTryBody)
1527  EmitStmt(cast<CXXTryStmt>(Body)->getTryBlock());
1528  else if (Body)
1529  EmitStmt(Body);
1530  else {
1531  assert(Dtor->isImplicit() && "bodyless dtor not implicit");
1532  // nothing to do besides what's in the epilogue
1533  }
1534  // -fapple-kext must inline any call to this dtor into
1535  // the caller's body.
1536  if (getLangOpts().AppleKext)
1537  CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
1538 
1539  break;
1540  }
1541 
1542  // Jump out through the epilogue cleanups.
1543  DtorEpilogue.ForceCleanup();
1544 
1545  // Exit the try if applicable.
1546  if (isTryBody)
1547  ExitCXXTryStmt(*cast<CXXTryStmt>(Body), true);
1548 }
1549 
1551  const CXXMethodDecl *AssignOp = cast<CXXMethodDecl>(CurGD.getDecl());
1552  const Stmt *RootS = AssignOp->getBody();
1553  assert(isa<CompoundStmt>(RootS) &&
1554  "Body of an implicit assignment operator should be compound stmt.");
1555  const CompoundStmt *RootCS = cast<CompoundStmt>(RootS);
1556 
1557  LexicalScope Scope(*this, RootCS->getSourceRange());
1558 
1559  incrementProfileCounter(RootCS);
1560  AssignmentMemcpyizer AM(*this, AssignOp, Args);
1561  for (auto *I : RootCS->body())
1562  AM.emitAssignment(I);
1563  AM.finish();
1564 }
1565 
1566 namespace {
1567  llvm::Value *LoadThisForDtorDelete(CodeGenFunction &CGF,
1568  const CXXDestructorDecl *DD) {
1569  if (Expr *ThisArg = DD->getOperatorDeleteThisArg())
1570  return CGF.EmitScalarExpr(ThisArg);
1571  return CGF.LoadCXXThis();
1572  }
1573 
1574  /// Call the operator delete associated with the current destructor.
1575  struct CallDtorDelete final : EHScopeStack::Cleanup {
1576  CallDtorDelete() {}
1577 
1578  void Emit(CodeGenFunction &CGF, Flags flags) override {
1579  const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
1580  const CXXRecordDecl *ClassDecl = Dtor->getParent();
1581  CGF.EmitDeleteCall(Dtor->getOperatorDelete(),
1582  LoadThisForDtorDelete(CGF, Dtor),
1583  CGF.getContext().getTagDeclType(ClassDecl));
1584  }
1585  };
1586 
1587  void EmitConditionalDtorDeleteCall(CodeGenFunction &CGF,
1588  llvm::Value *ShouldDeleteCondition,
1589  bool ReturnAfterDelete) {
1590  llvm::BasicBlock *callDeleteBB = CGF.createBasicBlock("dtor.call_delete");
1591  llvm::BasicBlock *continueBB = CGF.createBasicBlock("dtor.continue");
1592  llvm::Value *ShouldCallDelete
1593  = CGF.Builder.CreateIsNull(ShouldDeleteCondition);
1594  CGF.Builder.CreateCondBr(ShouldCallDelete, continueBB, callDeleteBB);
1595 
1596  CGF.EmitBlock(callDeleteBB);
1597  const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
1598  const CXXRecordDecl *ClassDecl = Dtor->getParent();
1599  CGF.EmitDeleteCall(Dtor->getOperatorDelete(),
1600  LoadThisForDtorDelete(CGF, Dtor),
1601  CGF.getContext().getTagDeclType(ClassDecl));
1602  assert(Dtor->getOperatorDelete()->isDestroyingOperatorDelete() ==
1603  ReturnAfterDelete &&
1604  "unexpected value for ReturnAfterDelete");
1605  if (ReturnAfterDelete)
1607  else
1608  CGF.Builder.CreateBr(continueBB);
1609 
1610  CGF.EmitBlock(continueBB);
1611  }
1612 
1613  struct CallDtorDeleteConditional final : EHScopeStack::Cleanup {
1614  llvm::Value *ShouldDeleteCondition;
1615 
1616  public:
1617  CallDtorDeleteConditional(llvm::Value *ShouldDeleteCondition)
1618  : ShouldDeleteCondition(ShouldDeleteCondition) {
1619  assert(ShouldDeleteCondition != nullptr);
1620  }
1621 
1622  void Emit(CodeGenFunction &CGF, Flags flags) override {
1623  EmitConditionalDtorDeleteCall(CGF, ShouldDeleteCondition,
1624  /*ReturnAfterDelete*/false);
1625  }
1626  };
1627 
1628  class DestroyField final : public EHScopeStack::Cleanup {
1629  const FieldDecl *field;
1630  CodeGenFunction::Destroyer *destroyer;
1631  bool useEHCleanupForArray;
1632 
1633  public:
1634  DestroyField(const FieldDecl *field, CodeGenFunction::Destroyer *destroyer,
1635  bool useEHCleanupForArray)
1636  : field(field), destroyer(destroyer),
1637  useEHCleanupForArray(useEHCleanupForArray) {}
1638 
1639  void Emit(CodeGenFunction &CGF, Flags flags) override {
1640  // Find the address of the field.
1641  Address thisValue = CGF.LoadCXXThisAddress();
1642  QualType RecordTy = CGF.getContext().getTagDeclType(field->getParent());
1643  LValue ThisLV = CGF.MakeAddrLValue(thisValue, RecordTy);
1644  LValue LV = CGF.EmitLValueForField(ThisLV, field);
1645  assert(LV.isSimple());
1646 
1647  CGF.emitDestroy(LV.getAddress(CGF), field->getType(), destroyer,
1648  flags.isForNormalCleanup() && useEHCleanupForArray);
1649  }
1650  };
1651 
1652  class DeclAsInlineDebugLocation {
1653  CGDebugInfo *DI;
1654  llvm::MDNode *InlinedAt;
1656 
1657  public:
1658  DeclAsInlineDebugLocation(CodeGenFunction &CGF, const NamedDecl &Decl)
1659  : DI(CGF.getDebugInfo()) {
1660  if (!DI)
1661  return;
1662  InlinedAt = DI->getInlinedAt();
1663  DI->setInlinedAt(CGF.Builder.getCurrentDebugLocation());
1664  Location.emplace(CGF, Decl.getLocation());
1665  }
1666 
1667  ~DeclAsInlineDebugLocation() {
1668  if (!DI)
1669  return;
1670  Location.reset();
1671  DI->setInlinedAt(InlinedAt);
1672  }
1673  };
1674 
1675  static void EmitSanitizerDtorCallback(
1676  CodeGenFunction &CGF, StringRef Name, llvm::Value *Ptr,
1677  llvm::Optional<CharUnits::QuantityType> PoisonSize = {}) {
1678  CodeGenFunction::SanitizerScope SanScope(&CGF);
1679  // Pass in void pointer and size of region as arguments to runtime
1680  // function
1682  CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy)};
1683  SmallVector<llvm::Type *, 2> ArgTypes = {CGF.VoidPtrTy};
1684 
1685  if (PoisonSize.has_value()) {
1686  Args.emplace_back(llvm::ConstantInt::get(CGF.SizeTy, *PoisonSize));
1687  ArgTypes.emplace_back(CGF.SizeTy);
1688  }
1689 
1690  llvm::FunctionType *FnType =
1691  llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
1692  llvm::FunctionCallee Fn = CGF.CGM.CreateRuntimeFunction(FnType, Name);
1693 
1694  CGF.EmitNounwindRuntimeCall(Fn, Args);
1695  }
1696 
1697  static void
1698  EmitSanitizerDtorFieldsCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
1699  CharUnits::QuantityType PoisonSize) {
1700  EmitSanitizerDtorCallback(CGF, "__sanitizer_dtor_callback_fields", Ptr,
1701  PoisonSize);
1702  }
1703 
1704  /// Poison base class with a trivial destructor.
1705  struct SanitizeDtorTrivialBase final : EHScopeStack::Cleanup {
1706  const CXXRecordDecl *BaseClass;
1707  bool BaseIsVirtual;
1708  SanitizeDtorTrivialBase(const CXXRecordDecl *Base, bool BaseIsVirtual)
1709  : BaseClass(Base), BaseIsVirtual(BaseIsVirtual) {}
1710 
1711  void Emit(CodeGenFunction &CGF, Flags flags) override {
1712  const CXXRecordDecl *DerivedClass =
1713  cast<CXXMethodDecl>(CGF.CurCodeDecl)->getParent();
1714 
1716  CGF.LoadCXXThisAddress(), DerivedClass, BaseClass, BaseIsVirtual);
1717 
1718  const ASTRecordLayout &BaseLayout =
1719  CGF.getContext().getASTRecordLayout(BaseClass);
1720  CharUnits BaseSize = BaseLayout.getSize();
1721 
1722  if (!BaseSize.isPositive())
1723  return;
1724 
1725  // Use the base class declaration location as inline DebugLocation. All
1726  // fields of the class are destroyed.
1727  DeclAsInlineDebugLocation InlineHere(CGF, *BaseClass);
1728  EmitSanitizerDtorFieldsCallback(CGF, Addr.getPointer(),
1729  BaseSize.getQuantity());
1730 
1731  // Prevent the current stack frame from disappearing from the stack trace.
1732  CGF.CurFn->addFnAttr("disable-tail-calls", "true");
1733  }
1734  };
1735 
1736  class SanitizeDtorFieldRange final : public EHScopeStack::Cleanup {
1737  const CXXDestructorDecl *Dtor;
1738  unsigned StartIndex;
1739  unsigned EndIndex;
1740 
1741  public:
1742  SanitizeDtorFieldRange(const CXXDestructorDecl *Dtor, unsigned StartIndex,
1743  unsigned EndIndex)
1744  : Dtor(Dtor), StartIndex(StartIndex), EndIndex(EndIndex) {}
1745 
1746  // Generate function call for handling object poisoning.
1747  // Disables tail call elimination, to prevent the current stack frame
1748  // from disappearing from the stack trace.
1749  void Emit(CodeGenFunction &CGF, Flags flags) override {
1750  const ASTContext &Context = CGF.getContext();
1751  const ASTRecordLayout &Layout =
1752  Context.getASTRecordLayout(Dtor->getParent());
1753 
1754  // It's a first trivial field so it should be at the begining of a char,
1755  // still round up start offset just in case.
1756  CharUnits PoisonStart = Context.toCharUnitsFromBits(
1757  Layout.getFieldOffset(StartIndex) + Context.getCharWidth() - 1);
1758  llvm::ConstantInt *OffsetSizePtr =
1759  llvm::ConstantInt::get(CGF.SizeTy, PoisonStart.getQuantity());
1760 
1761  llvm::Value *OffsetPtr = CGF.Builder.CreateGEP(
1762  CGF.Int8Ty,
1763  CGF.Builder.CreateBitCast(CGF.LoadCXXThis(), CGF.Int8PtrTy),
1764  OffsetSizePtr);
1765 
1766  CharUnits PoisonEnd;
1767  if (EndIndex >= Layout.getFieldCount()) {
1768  PoisonEnd = Layout.getNonVirtualSize();
1769  } else {
1770  PoisonEnd =
1771  Context.toCharUnitsFromBits(Layout.getFieldOffset(EndIndex));
1772  }
1773  CharUnits PoisonSize = PoisonEnd - PoisonStart;
1774  if (!PoisonSize.isPositive())
1775  return;
1776 
1777  // Use the top field declaration location as inline DebugLocation.
1778  DeclAsInlineDebugLocation InlineHere(
1779  CGF, **std::next(Dtor->getParent()->field_begin(), StartIndex));
1780  EmitSanitizerDtorFieldsCallback(CGF, OffsetPtr, PoisonSize.getQuantity());
1781 
1782  // Prevent the current stack frame from disappearing from the stack trace.
1783  CGF.CurFn->addFnAttr("disable-tail-calls", "true");
1784  }
1785  };
1786 
1787  class SanitizeDtorVTable final : public EHScopeStack::Cleanup {
1788  const CXXDestructorDecl *Dtor;
1789 
1790  public:
1791  SanitizeDtorVTable(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
1792 
1793  // Generate function call for handling vtable pointer poisoning.
1794  void Emit(CodeGenFunction &CGF, Flags flags) override {
1795  assert(Dtor->getParent()->isDynamicClass());
1796  (void)Dtor;
1797  // Poison vtable and vtable ptr if they exist for this class.
1798  llvm::Value *VTablePtr = CGF.LoadCXXThis();
1799 
1800  // Pass in void pointer and size of region as arguments to runtime
1801  // function
1802  EmitSanitizerDtorCallback(CGF, "__sanitizer_dtor_callback_vptr",
1803  VTablePtr);
1804  }
1805  };
1806 
1807  class SanitizeDtorCleanupBuilder {
1808  ASTContext &Context;
1809  EHScopeStack &EHStack;
1810  const CXXDestructorDecl *DD;
1811  llvm::Optional<unsigned> StartIndex;
1812 
1813  public:
1814  SanitizeDtorCleanupBuilder(ASTContext &Context, EHScopeStack &EHStack,
1815  const CXXDestructorDecl *DD)
1816  : Context(Context), EHStack(EHStack), DD(DD), StartIndex(llvm::None) {}
1817  void PushCleanupForField(const FieldDecl *Field) {
1818  if (Field->isZeroSize(Context))
1819  return;
1820  unsigned FieldIndex = Field->getFieldIndex();
1821  if (FieldHasTrivialDestructorBody(Context, Field)) {
1822  if (!StartIndex)
1823  StartIndex = FieldIndex;
1824  } else if (StartIndex) {
1825  EHStack.pushCleanup<SanitizeDtorFieldRange>(
1826  NormalAndEHCleanup, DD, StartIndex.value(), FieldIndex);
1827  StartIndex = None;
1828  }
1829  }
1830  void End() {
1831  if (StartIndex)
1832  EHStack.pushCleanup<SanitizeDtorFieldRange>(NormalAndEHCleanup, DD,
1833  StartIndex.value(), -1);
1834  }
1835  };
1836 } // end anonymous namespace
1837 
1838 /// Emit all code that comes at the end of class's
1839 /// destructor. This is to call destructors on members and base classes
1840 /// in reverse order of their construction.
1841 ///
1842 /// For a deleting destructor, this also handles the case where a destroying
1843 /// operator delete completely overrides the definition.
1845  CXXDtorType DtorType) {
1846  assert((!DD->isTrivial() || DD->hasAttr<DLLExportAttr>()) &&
1847  "Should not emit dtor epilogue for non-exported trivial dtor!");
1848 
1849  // The deleting-destructor phase just needs to call the appropriate
1850  // operator delete that Sema picked up.
1851  if (DtorType == Dtor_Deleting) {
1852  assert(DD->getOperatorDelete() &&
1853  "operator delete missing - EnterDtorCleanups");
1854  if (CXXStructorImplicitParamValue) {
1855  // If there is an implicit param to the deleting dtor, it's a boolean
1856  // telling whether this is a deleting destructor.
1858  EmitConditionalDtorDeleteCall(*this, CXXStructorImplicitParamValue,
1859  /*ReturnAfterDelete*/true);
1860  else
1861  EHStack.pushCleanup<CallDtorDeleteConditional>(
1862  NormalAndEHCleanup, CXXStructorImplicitParamValue);
1863  } else {
1865  const CXXRecordDecl *ClassDecl = DD->getParent();
1867  LoadThisForDtorDelete(*this, DD),
1868  getContext().getTagDeclType(ClassDecl));
1870  } else {
1871  EHStack.pushCleanup<CallDtorDelete>(NormalAndEHCleanup);
1872  }
1873  }
1874  return;
1875  }
1876 
1877  const CXXRecordDecl *ClassDecl = DD->getParent();
1878 
1879  // Unions have no bases and do not call field destructors.
1880  if (ClassDecl->isUnion())
1881  return;
1882 
1883  // The complete-destructor phase just destructs all the virtual bases.
1884  if (DtorType == Dtor_Complete) {
1885  // Poison the vtable pointer such that access after the base
1886  // and member destructors are invoked is invalid.
1887  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
1888  SanOpts.has(SanitizerKind::Memory) && ClassDecl->getNumVBases() &&
1889  ClassDecl->isPolymorphic())
1890  EHStack.pushCleanup<SanitizeDtorVTable>(NormalAndEHCleanup, DD);
1891 
1892  // We push them in the forward order so that they'll be popped in
1893  // the reverse order.
1894  for (const auto &Base : ClassDecl->vbases()) {
1895  auto *BaseClassDecl =
1896  cast<CXXRecordDecl>(Base.getType()->castAs<RecordType>()->getDecl());
1897 
1898  if (BaseClassDecl->hasTrivialDestructor()) {
1899  // Under SanitizeMemoryUseAfterDtor, poison the trivial base class
1900  // memory. For non-trival base classes the same is done in the class
1901  // destructor.
1902  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
1903  SanOpts.has(SanitizerKind::Memory) && !BaseClassDecl->isEmpty())
1904  EHStack.pushCleanup<SanitizeDtorTrivialBase>(NormalAndEHCleanup,
1905  BaseClassDecl,
1906  /*BaseIsVirtual*/ true);
1907  } else {
1908  EHStack.pushCleanup<CallBaseDtor>(NormalAndEHCleanup, BaseClassDecl,
1909  /*BaseIsVirtual*/ true);
1910  }
1911  }
1912 
1913  return;
1914  }
1915 
1916  assert(DtorType == Dtor_Base);
1917  // Poison the vtable pointer if it has no virtual bases, but inherits
1918  // virtual functions.
1919  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
1920  SanOpts.has(SanitizerKind::Memory) && !ClassDecl->getNumVBases() &&
1921  ClassDecl->isPolymorphic())
1922  EHStack.pushCleanup<SanitizeDtorVTable>(NormalAndEHCleanup, DD);
1923 
1924  // Destroy non-virtual bases.
1925  for (const auto &Base : ClassDecl->bases()) {
1926  // Ignore virtual bases.
1927  if (Base.isVirtual())
1928  continue;
1929 
1930  CXXRecordDecl *BaseClassDecl = Base.getType()->getAsCXXRecordDecl();
1931 
1932  if (BaseClassDecl->hasTrivialDestructor()) {
1933  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
1934  SanOpts.has(SanitizerKind::Memory) && !BaseClassDecl->isEmpty())
1935  EHStack.pushCleanup<SanitizeDtorTrivialBase>(NormalAndEHCleanup,
1936  BaseClassDecl,
1937  /*BaseIsVirtual*/ false);
1938  } else {
1939  EHStack.pushCleanup<CallBaseDtor>(NormalAndEHCleanup, BaseClassDecl,
1940  /*BaseIsVirtual*/ false);
1941  }
1942  }
1943 
1944  // Poison fields such that access after their destructors are
1945  // invoked, and before the base class destructor runs, is invalid.
1946  bool SanitizeFields = CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
1947  SanOpts.has(SanitizerKind::Memory);
1948  SanitizeDtorCleanupBuilder SanitizeBuilder(getContext(), EHStack, DD);
1949 
1950  // Destroy direct fields.
1951  for (const auto *Field : ClassDecl->fields()) {
1952  if (SanitizeFields)
1953  SanitizeBuilder.PushCleanupForField(Field);
1954 
1955  QualType type = Field->getType();
1956  QualType::DestructionKind dtorKind = type.isDestructedType();
1957  if (!dtorKind)
1958  continue;
1959 
1960  // Anonymous union members do not have their destructors called.
1961  const RecordType *RT = type->getAsUnionType();
1962  if (RT && RT->getDecl()->isAnonymousStructOrUnion())
1963  continue;
1964 
1965  CleanupKind cleanupKind = getCleanupKind(dtorKind);
1966  EHStack.pushCleanup<DestroyField>(
1967  cleanupKind, Field, getDestroyer(dtorKind), cleanupKind & EHCleanup);
1968  }
1969 
1970  if (SanitizeFields)
1971  SanitizeBuilder.End();
1972 }
1973 
1974 /// EmitCXXAggrConstructorCall - Emit a loop to call a particular
1975 /// constructor for each of several members of an array.
1976 ///
1977 /// \param ctor the constructor to call for each element
1978 /// \param arrayType the type of the array to initialize
1979 /// \param arrayBegin an arrayType*
1980 /// \param zeroInitialize true if each element should be
1981 /// zero-initialized before it is constructed
1983  const CXXConstructorDecl *ctor, const ArrayType *arrayType,
1984  Address arrayBegin, const CXXConstructExpr *E, bool NewPointerIsChecked,
1985  bool zeroInitialize) {
1986  QualType elementType;
1987  llvm::Value *numElements =
1988  emitArrayLength(arrayType, elementType, arrayBegin);
1989 
1990  EmitCXXAggrConstructorCall(ctor, numElements, arrayBegin, E,
1991  NewPointerIsChecked, zeroInitialize);
1992 }
1993 
1994 /// EmitCXXAggrConstructorCall - Emit a loop to call a particular
1995 /// constructor for each of several members of an array.
1996 ///
1997 /// \param ctor the constructor to call for each element
1998 /// \param numElements the number of elements in the array;
1999 /// may be zero
2000 /// \param arrayBase a T*, where T is the type constructed by ctor
2001 /// \param zeroInitialize true if each element should be
2002 /// zero-initialized before it is constructed
2004  llvm::Value *numElements,
2005  Address arrayBase,
2006  const CXXConstructExpr *E,
2007  bool NewPointerIsChecked,
2008  bool zeroInitialize) {
2009  // It's legal for numElements to be zero. This can happen both
2010  // dynamically, because x can be zero in 'new A[x]', and statically,
2011  // because of GCC extensions that permit zero-length arrays. There
2012  // are probably legitimate places where we could assume that this
2013  // doesn't happen, but it's not clear that it's worth it.
2014  llvm::BranchInst *zeroCheckBranch = nullptr;
2015 
2016  // Optimize for a constant count.
2017  llvm::ConstantInt *constantCount
2018  = dyn_cast<llvm::ConstantInt>(numElements);
2019  if (constantCount) {
2020  // Just skip out if the constant count is zero.
2021  if (constantCount->isZero()) return;
2022 
2023  // Otherwise, emit the check.
2024  } else {
2025  llvm::BasicBlock *loopBB = createBasicBlock("new.ctorloop");
2026  llvm::Value *iszero = Builder.CreateIsNull(numElements, "isempty");
2027  zeroCheckBranch = Builder.CreateCondBr(iszero, loopBB, loopBB);
2028  EmitBlock(loopBB);
2029  }
2030 
2031  // Find the end of the array.
2032  llvm::Type *elementType = arrayBase.getElementType();
2033  llvm::Value *arrayBegin = arrayBase.getPointer();
2034  llvm::Value *arrayEnd = Builder.CreateInBoundsGEP(
2035  elementType, arrayBegin, numElements, "arrayctor.end");
2036 
2037  // Enter the loop, setting up a phi for the current location to initialize.
2038  llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
2039  llvm::BasicBlock *loopBB = createBasicBlock("arrayctor.loop");
2040  EmitBlock(loopBB);
2041  llvm::PHINode *cur = Builder.CreatePHI(arrayBegin->getType(), 2,
2042  "arrayctor.cur");
2043  cur->addIncoming(arrayBegin, entryBB);
2044 
2045  // Inside the loop body, emit the constructor call on the array element.
2046 
2047  // The alignment of the base, adjusted by the size of a single element,
2048  // provides a conservative estimate of the alignment of every element.
2049  // (This assumes we never start tracking offsetted alignments.)
2050  //
2051  // Note that these are complete objects and so we don't need to
2052  // use the non-virtual size or alignment.
2054  CharUnits eltAlignment =
2055  arrayBase.getAlignment()
2056  .alignmentOfArrayElement(getContext().getTypeSizeInChars(type));
2057  Address curAddr = Address(cur, elementType, eltAlignment);
2058 
2059  // Zero initialize the storage, if requested.
2060  if (zeroInitialize)
2061  EmitNullInitialization(curAddr, type);
2062 
2063  // C++ [class.temporary]p4:
2064  // There are two contexts in which temporaries are destroyed at a different
2065  // point than the end of the full-expression. The first context is when a
2066  // default constructor is called to initialize an element of an array.
2067  // If the constructor has one or more default arguments, the destruction of
2068  // every temporary created in a default argument expression is sequenced
2069  // before the construction of the next array element, if any.
2070 
2071  {
2072  RunCleanupsScope Scope(*this);
2073 
2074  // Evaluate the constructor and its arguments in a regular
2075  // partial-destroy cleanup.
2076  if (getLangOpts().Exceptions &&
2077  !ctor->getParent()->hasTrivialDestructor()) {
2078  Destroyer *destroyer = destroyCXXObject;
2079  pushRegularPartialArrayCleanup(arrayBegin, cur, type, eltAlignment,
2080  *destroyer);
2081  }
2082  auto currAVS = AggValueSlot::forAddr(
2083  curAddr, type.getQualifiers(), AggValueSlot::IsDestructed,
2086  NewPointerIsChecked ? AggValueSlot::IsSanitizerChecked
2088  EmitCXXConstructorCall(ctor, Ctor_Complete, /*ForVirtualBase=*/false,
2089  /*Delegating=*/false, currAVS, E);
2090  }
2091 
2092  // Go to the next element.
2093  llvm::Value *next = Builder.CreateInBoundsGEP(
2094  elementType, cur, llvm::ConstantInt::get(SizeTy, 1), "arrayctor.next");
2095  cur->addIncoming(next, Builder.GetInsertBlock());
2096 
2097  // Check whether that's the end of the loop.
2098  llvm::Value *done = Builder.CreateICmpEQ(next, arrayEnd, "arrayctor.done");
2099  llvm::BasicBlock *contBB = createBasicBlock("arrayctor.cont");
2100  Builder.CreateCondBr(done, contBB, loopBB);
2101 
2102  // Patch the earlier check to skip over the loop.
2103  if (zeroCheckBranch) zeroCheckBranch->setSuccessor(0, contBB);
2104 
2105  EmitBlock(contBB);
2106 }
2107 
2109  Address addr,
2110  QualType type) {
2111  const RecordType *rtype = type->castAs<RecordType>();
2112  const CXXRecordDecl *record = cast<CXXRecordDecl>(rtype->getDecl());
2113  const CXXDestructorDecl *dtor = record->getDestructor();
2114  assert(!dtor->isTrivial());
2115  CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*for vbase*/ false,
2116  /*Delegating=*/false, addr, type);
2117 }
2118 
2120  CXXCtorType Type,
2121  bool ForVirtualBase,
2122  bool Delegating,
2123  AggValueSlot ThisAVS,
2124  const CXXConstructExpr *E) {
2125  CallArgList Args;
2126  Address This = ThisAVS.getAddress();
2127  LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace();
2128  QualType ThisType = D->getThisType();
2129  LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace();
2130  llvm::Value *ThisPtr = This.getPointer();
2131 
2132  if (SlotAS != ThisAS) {
2133  unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
2134  llvm::Type *NewType = llvm::PointerType::getWithSamePointeeType(
2135  This.getType(), TargetThisAS);
2136  ThisPtr = getTargetHooks().performAddrSpaceCast(*this, This.getPointer(),
2137  ThisAS, SlotAS, NewType);
2138  }
2139 
2140  // Push the this ptr.
2141  Args.add(RValue::get(ThisPtr), D->getThisType());
2142 
2143  // If this is a trivial constructor, emit a memcpy now before we lose
2144  // the alignment information on the argument.
2145  // FIXME: It would be better to preserve alignment information into CallArg.
2147  assert(E->getNumArgs() == 1 && "unexpected argcount for trivial ctor");
2148 
2149  const Expr *Arg = E->getArg(0);
2150  LValue Src = EmitLValue(Arg);
2151  QualType DestTy = getContext().getTypeDeclType(D->getParent());
2152  LValue Dest = MakeAddrLValue(This, DestTy);
2153  EmitAggregateCopyCtor(Dest, Src, ThisAVS.mayOverlap());
2154  return;
2155  }
2156 
2157  // Add the rest of the user-supplied arguments.
2158  const FunctionProtoType *FPT = D->getType()->castAs<FunctionProtoType>();
2162  EmitCallArgs(Args, FPT, E->arguments(), E->getConstructor(),
2163  /*ParamsToSkip*/ 0, Order);
2164 
2165  EmitCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args,
2166  ThisAVS.mayOverlap(), E->getExprLoc(),
2167  ThisAVS.isSanitizerChecked());
2168 }
2169 
2171  const CXXConstructorDecl *Ctor,
2172  CXXCtorType Type, CallArgList &Args) {
2173  // We can't forward a variadic call.
2174  if (Ctor->isVariadic())
2175  return false;
2176 
2178  // If the parameters are callee-cleanup, it's not safe to forward.
2179  for (auto *P : Ctor->parameters())
2180  if (P->needsDestruction(CGF.getContext()))
2181  return false;
2182 
2183  // Likewise if they're inalloca.
2184  const CGFunctionInfo &Info =
2185  CGF.CGM.getTypes().arrangeCXXConstructorCall(Args, Ctor, Type, 0, 0);
2186  if (Info.usesInAlloca())
2187  return false;
2188  }
2189 
2190  // Anything else should be OK.
2191  return true;
2192 }
2193 
2195  CXXCtorType Type,
2196  bool ForVirtualBase,
2197  bool Delegating,
2198  Address This,
2199  CallArgList &Args,
2200  AggValueSlot::Overlap_t Overlap,
2201  SourceLocation Loc,
2202  bool NewPointerIsChecked) {
2203  const CXXRecordDecl *ClassDecl = D->getParent();
2204 
2205  if (!NewPointerIsChecked)
2207  getContext().getRecordType(ClassDecl), CharUnits::Zero());
2208 
2209  if (D->isTrivial() && D->isDefaultConstructor()) {
2210  assert(Args.size() == 1 && "trivial default ctor with args");
2211  return;
2212  }
2213 
2214  // If this is a trivial constructor, just emit what's needed. If this is a
2215  // union copy constructor, we must emit a memcpy, because the AST does not
2216  // model that copy.
2218  assert(Args.size() == 2 && "unexpected argcount for trivial ctor");
2219 
2220  QualType SrcTy = D->getParamDecl(0)->getType().getNonReferenceType();
2221  Address Src = Address(Args[1].getRValue(*this).getScalarVal(), ConvertTypeForMem(SrcTy),
2222  CGM.getNaturalTypeAlignment(SrcTy));
2223  LValue SrcLVal = MakeAddrLValue(Src, SrcTy);
2224  QualType DestTy = getContext().getTypeDeclType(ClassDecl);
2225  LValue DestLVal = MakeAddrLValue(This, DestTy);
2226  EmitAggregateCopyCtor(DestLVal, SrcLVal, Overlap);
2227  return;
2228  }
2229 
2230  bool PassPrototypeArgs = true;
2231  // Check whether we can actually emit the constructor before trying to do so.
2232  if (auto Inherited = D->getInheritedConstructor()) {
2233  PassPrototypeArgs = getTypes().inheritingCtorHasParams(Inherited, Type);
2234  if (PassPrototypeArgs && !canEmitDelegateCallArgs(*this, D, Type, Args)) {
2235  EmitInlinedInheritingCXXConstructorCall(D, Type, ForVirtualBase,
2236  Delegating, Args);
2237  return;
2238  }
2239  }
2240 
2241  // Insert any ABI-specific implicit constructor arguments.
2243  CGM.getCXXABI().addImplicitConstructorArgs(*this, D, Type, ForVirtualBase,
2244  Delegating, Args);
2245 
2246  // Emit the call.
2247  llvm::Constant *CalleePtr = CGM.getAddrOfCXXStructor(GlobalDecl(D, Type));
2249  Args, D, Type, ExtraArgs.Prefix, ExtraArgs.Suffix, PassPrototypeArgs);
2250  CGCallee Callee = CGCallee::forDirect(CalleePtr, GlobalDecl(D, Type));
2251  EmitCall(Info, Callee, ReturnValueSlot(), Args, nullptr, false, Loc);
2252 
2253  // Generate vtable assumptions if we're constructing a complete object
2254  // with a vtable. We don't do this for base subobjects for two reasons:
2255  // first, it's incorrect for classes with virtual bases, and second, we're
2256  // about to overwrite the vptrs anyway.
2257  // We also have to make sure if we can refer to vtable:
2258  // - Otherwise we can refer to vtable if it's safe to speculatively emit.
2259  // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
2260  // sure that definition of vtable is not hidden,
2261  // then we are always safe to refer to it.
2262  // FIXME: It looks like InstCombine is very inefficient on dealing with
2263  // assumes. Make assumption loads require -fstrict-vtable-pointers temporarily.
2264  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2265  ClassDecl->isDynamicClass() && Type != Ctor_Base &&
2266  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
2267  CGM.getCodeGenOpts().StrictVTablePointers)
2268  EmitVTableAssumptionLoads(ClassDecl, This);
2269 }
2270 
2272  const CXXConstructorDecl *D, bool ForVirtualBase, Address This,
2273  bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E) {
2274  CallArgList Args;
2275  CallArg ThisArg(RValue::get(This.getPointer()), D->getThisType());
2276 
2277  // Forward the parameters.
2278  if (InheritedFromVBase &&
2280  // Nothing to do; this construction is not responsible for constructing
2281  // the base class containing the inherited constructor.
2282  // FIXME: Can we just pass undef's for the remaining arguments if we don't
2283  // have constructor variants?
2284  Args.push_back(ThisArg);
2285  } else if (!CXXInheritedCtorInitExprArgs.empty()) {
2286  // The inheriting constructor was inlined; just inject its arguments.
2287  assert(CXXInheritedCtorInitExprArgs.size() >= D->getNumParams() &&
2288  "wrong number of parameters for inherited constructor call");
2289  Args = CXXInheritedCtorInitExprArgs;
2290  Args[0] = ThisArg;
2291  } else {
2292  // The inheriting constructor was not inlined. Emit delegating arguments.
2293  Args.push_back(ThisArg);
2294  const auto *OuterCtor = cast<CXXConstructorDecl>(CurCodeDecl);
2295  assert(OuterCtor->getNumParams() == D->getNumParams());
2296  assert(!OuterCtor->isVariadic() && "should have been inlined");
2297 
2298  for (const auto *Param : OuterCtor->parameters()) {
2299  assert(getContext().hasSameUnqualifiedType(
2300  OuterCtor->getParamDecl(Param->getFunctionScopeIndex())->getType(),
2301  Param->getType()));
2302  EmitDelegateCallArg(Args, Param, E->getLocation());
2303 
2304  // Forward __attribute__(pass_object_size).
2305  if (Param->hasAttr<PassObjectSizeAttr>()) {
2306  auto *POSParam = SizeArguments[Param];
2307  assert(POSParam && "missing pass_object_size value for forwarding");
2308  EmitDelegateCallArg(Args, POSParam, E->getLocation());
2309  }
2310  }
2311  }
2312 
2313  EmitCXXConstructorCall(D, Ctor_Base, ForVirtualBase, /*Delegating*/false,
2315  E->getLocation(), /*NewPointerIsChecked*/true);
2316 }
2317 
2319  const CXXConstructorDecl *Ctor, CXXCtorType CtorType, bool ForVirtualBase,
2320  bool Delegating, CallArgList &Args) {
2321  GlobalDecl GD(Ctor, CtorType);
2323  ApplyInlineDebugLocation DebugScope(*this, GD);
2324  RunCleanupsScope RunCleanups(*this);
2325 
2326  // Save the arguments to be passed to the inherited constructor.
2327  CXXInheritedCtorInitExprArgs = Args;
2328 
2329  FunctionArgList Params;
2330  QualType RetType = BuildFunctionArgList(CurGD, Params);
2331  FnRetTy = RetType;
2332 
2333  // Insert any ABI-specific implicit constructor arguments.
2334  CGM.getCXXABI().addImplicitConstructorArgs(*this, Ctor, CtorType,
2335  ForVirtualBase, Delegating, Args);
2336 
2337  // Emit a simplified prolog. We only need to emit the implicit params.
2338  assert(Args.size() >= Params.size() && "too few arguments for call");
2339  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
2340  if (I < Params.size() && isa<ImplicitParamDecl>(Params[I])) {
2341  const RValue &RV = Args[I].getRValue(*this);
2342  assert(!RV.isComplex() && "complex indirect params not supported");
2343  ParamValue Val = RV.isScalar()
2346  EmitParmDecl(*Params[I], Val, I + 1);
2347  }
2348  }
2349 
2350  // Create a return value slot if the ABI implementation wants one.
2351  // FIXME: This is dumb, we should ask the ABI not to try to set the return
2352  // value instead.
2353  if (!RetType->isVoidType())
2354  ReturnValue = CreateIRTemp(RetType, "retval.inhctor");
2355 
2357  CXXThisValue = CXXABIThisValue;
2358 
2359  // Directly emit the constructor initializers.
2360  EmitCtorPrologue(Ctor, CtorType, Params);
2361 }
2362 
2364  llvm::Value *VTableGlobal =
2366  if (!VTableGlobal)
2367  return;
2368 
2369  // We can just use the base offset in the complete class.
2370  CharUnits NonVirtualOffset = Vptr.Base.getBaseOffset();
2371 
2372  if (!NonVirtualOffset.isZero())
2373  This =
2374  ApplyNonVirtualAndVirtualOffset(*this, This, NonVirtualOffset, nullptr,
2375  Vptr.VTableClass, Vptr.NearestVBase);
2376 
2377  llvm::Value *VPtrValue =
2378  GetVTablePtr(This, VTableGlobal->getType(), Vptr.VTableClass);
2379  llvm::Value *Cmp =
2380  Builder.CreateICmpEQ(VPtrValue, VTableGlobal, "cmp.vtables");
2381  Builder.CreateAssumption(Cmp);
2382 }
2383 
2385  Address This) {
2386  if (CGM.getCXXABI().doStructorsInitializeVPtrs(ClassDecl))
2387  for (const VPtr &Vptr : getVTablePointers(ClassDecl))
2389 }
2390 
2391 void
2393  Address This, Address Src,
2394  const CXXConstructExpr *E) {
2395  const FunctionProtoType *FPT = D->getType()->castAs<FunctionProtoType>();
2396 
2397  CallArgList Args;
2398 
2399  // Push the this ptr.
2400  Args.add(RValue::get(This.getPointer()), D->getThisType());
2401 
2402  // Push the src ptr.
2403  QualType QT = *(FPT->param_type_begin());
2404  llvm::Type *t = CGM.getTypes().ConvertType(QT);
2405  llvm::Value *SrcVal = Builder.CreateBitCast(Src.getPointer(), t);
2406  Args.add(RValue::get(SrcVal), QT);
2407 
2408  // Skip over first argument (Src).
2409  EmitCallArgs(Args, FPT, drop_begin(E->arguments(), 1), E->getConstructor(),
2410  /*ParamsToSkip*/ 1);
2411 
2412  EmitCXXConstructorCall(D, Ctor_Complete, /*ForVirtualBase*/false,
2413  /*Delegating*/false, This, Args,
2415  /*NewPointerIsChecked*/false);
2416 }
2417 
2418 void
2420  CXXCtorType CtorType,
2421  const FunctionArgList &Args,
2422  SourceLocation Loc) {
2423  CallArgList DelegateArgs;
2424 
2425  FunctionArgList::const_iterator I = Args.begin(), E = Args.end();
2426  assert(I != E && "no parameters to constructor");
2427 
2428  // this
2430  DelegateArgs.add(RValue::get(This.getPointer()), (*I)->getType());
2431  ++I;
2432 
2433  // FIXME: The location of the VTT parameter in the parameter list is
2434  // specific to the Itanium ABI and shouldn't be hardcoded here.
2436  assert(I != E && "cannot skip vtt parameter, already done with args");
2437  assert((*I)->getType()->isPointerType() &&
2438  "skipping parameter not of vtt type");
2439  ++I;
2440  }
2441 
2442  // Explicit arguments.
2443  for (; I != E; ++I) {
2444  const VarDecl *param = *I;
2445  // FIXME: per-argument source location
2446  EmitDelegateCallArg(DelegateArgs, param, Loc);
2447  }
2448 
2449  EmitCXXConstructorCall(Ctor, CtorType, /*ForVirtualBase=*/false,
2450  /*Delegating=*/true, This, DelegateArgs,
2452  /*NewPointerIsChecked=*/true);
2453 }
2454 
2455 namespace {
2456  struct CallDelegatingCtorDtor final : EHScopeStack::Cleanup {
2457  const CXXDestructorDecl *Dtor;
2458  Address Addr;
2459  CXXDtorType Type;
2460 
2461  CallDelegatingCtorDtor(const CXXDestructorDecl *D, Address Addr,
2462  CXXDtorType Type)
2463  : Dtor(D), Addr(Addr), Type(Type) {}
2464 
2465  void Emit(CodeGenFunction &CGF, Flags flags) override {
2466  // We are calling the destructor from within the constructor.
2467  // Therefore, "this" should have the expected type.
2468  QualType ThisTy = Dtor->getThisObjectType();
2469  CGF.EmitCXXDestructorCall(Dtor, Type, /*ForVirtualBase=*/false,
2470  /*Delegating=*/true, Addr, ThisTy);
2471  }
2472  };
2473 } // end anonymous namespace
2474 
2475 void
2477  const FunctionArgList &Args) {
2478  assert(Ctor->isDelegatingConstructor());
2479 
2480  Address ThisPtr = LoadCXXThisAddress();
2481 
2482  AggValueSlot AggSlot =
2483  AggValueSlot::forAddr(ThisPtr, Qualifiers(),
2489  // Checks are made by the code that calls constructor.
2491 
2492  EmitAggExpr(Ctor->init_begin()[0]->getInit(), AggSlot);
2493 
2494  const CXXRecordDecl *ClassDecl = Ctor->getParent();
2495  if (CGM.getLangOpts().Exceptions && !ClassDecl->hasTrivialDestructor()) {
2496  CXXDtorType Type =
2498 
2499  EHStack.pushCleanup<CallDelegatingCtorDtor>(EHCleanup,
2500  ClassDecl->getDestructor(),
2501  ThisPtr, Type);
2502  }
2503 }
2504 
2506  CXXDtorType Type,
2507  bool ForVirtualBase,
2508  bool Delegating, Address This,
2509  QualType ThisTy) {
2510  CGM.getCXXABI().EmitDestructorCall(*this, DD, Type, ForVirtualBase,
2511  Delegating, This, ThisTy);
2512 }
2513 
2514 namespace {
2515  struct CallLocalDtor final : EHScopeStack::Cleanup {
2516  const CXXDestructorDecl *Dtor;
2517  Address Addr;
2518  QualType Ty;
2519 
2520  CallLocalDtor(const CXXDestructorDecl *D, Address Addr, QualType Ty)
2521  : Dtor(D), Addr(Addr), Ty(Ty) {}
2522 
2523  void Emit(CodeGenFunction &CGF, Flags flags) override {
2525  /*ForVirtualBase=*/false,
2526  /*Delegating=*/false, Addr, Ty);
2527  }
2528  };
2529 } // end anonymous namespace
2530 
2532  QualType T, Address Addr) {
2533  EHStack.pushCleanup<CallLocalDtor>(NormalAndEHCleanup, D, Addr, T);
2534 }
2535 
2537  CXXRecordDecl *ClassDecl = T->getAsCXXRecordDecl();
2538  if (!ClassDecl) return;
2539  if (ClassDecl->hasTrivialDestructor()) return;
2540 
2541  const CXXDestructorDecl *D = ClassDecl->getDestructor();
2542  assert(D && D->isUsed() && "destructor not marked as used!");
2543  PushDestructorCleanup(D, T, Addr);
2544 }
2545 
2547  // Compute the address point.
2548  llvm::Value *VTableAddressPoint =
2550  *this, Vptr.VTableClass, Vptr.Base, Vptr.NearestVBase);
2551 
2552  if (!VTableAddressPoint)
2553  return;
2554 
2555  // Compute where to store the address point.
2556  llvm::Value *VirtualOffset = nullptr;
2557  CharUnits NonVirtualOffset = CharUnits::Zero();
2558 
2559  if (CGM.getCXXABI().isVirtualOffsetNeededForVTableField(*this, Vptr)) {
2560  // We need to use the virtual base offset offset because the virtual base
2561  // might have a different offset in the most derived class.
2562 
2563  VirtualOffset = CGM.getCXXABI().GetVirtualBaseClassOffset(
2564  *this, LoadCXXThisAddress(), Vptr.VTableClass, Vptr.NearestVBase);
2565  NonVirtualOffset = Vptr.OffsetFromNearestVBase;
2566  } else {
2567  // We can just use the base offset in the complete class.
2568  NonVirtualOffset = Vptr.Base.getBaseOffset();
2569  }
2570 
2571  // Apply the offsets.
2572  Address VTableField = LoadCXXThisAddress();
2573  if (!NonVirtualOffset.isZero() || VirtualOffset)
2574  VTableField = ApplyNonVirtualAndVirtualOffset(
2575  *this, VTableField, NonVirtualOffset, VirtualOffset, Vptr.VTableClass,
2576  Vptr.NearestVBase);
2577 
2578  // Finally, store the address point. Use the same LLVM types as the field to
2579  // support optimization.
2580  unsigned GlobalsAS = CGM.getDataLayout().getDefaultGlobalsAddressSpace();
2581  unsigned ProgAS = CGM.getDataLayout().getProgramAddressSpace();
2582  llvm::Type *VTablePtrTy =
2583  llvm::FunctionType::get(CGM.Int32Ty, /*isVarArg=*/true)
2584  ->getPointerTo(ProgAS)
2585  ->getPointerTo(GlobalsAS);
2586  // vtable field is derived from `this` pointer, therefore they should be in
2587  // the same addr space. Note that this might not be LLVM address space 0.
2588  VTableField = Builder.CreateElementBitCast(VTableField, VTablePtrTy);
2589  VTableAddressPoint = Builder.CreateBitCast(VTableAddressPoint, VTablePtrTy);
2590 
2591  llvm::StoreInst *Store = Builder.CreateStore(VTableAddressPoint, VTableField);
2592  TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTablePtrTy);
2594  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2595  CGM.getCodeGenOpts().StrictVTablePointers)
2597 }
2598 
2601  CodeGenFunction::VPtrsVector VPtrsResult;
2602  VisitedVirtualBasesSetTy VBases;
2604  /*NearestVBase=*/nullptr,
2605  /*OffsetFromNearestVBase=*/CharUnits::Zero(),
2606  /*BaseIsNonVirtualPrimaryBase=*/false, VTableClass, VBases,
2607  VPtrsResult);
2608  return VPtrsResult;
2609 }
2610 
2612  const CXXRecordDecl *NearestVBase,
2613  CharUnits OffsetFromNearestVBase,
2614  bool BaseIsNonVirtualPrimaryBase,
2615  const CXXRecordDecl *VTableClass,
2616  VisitedVirtualBasesSetTy &VBases,
2617  VPtrsVector &Vptrs) {
2618  // If this base is a non-virtual primary base the address point has already
2619  // been set.
2620  if (!BaseIsNonVirtualPrimaryBase) {
2621  // Initialize the vtable pointer for this base.
2622  VPtr Vptr = {Base, NearestVBase, OffsetFromNearestVBase, VTableClass};
2623  Vptrs.push_back(Vptr);
2624  }
2625 
2626  const CXXRecordDecl *RD = Base.getBase();
2627 
2628  // Traverse bases.
2629  for (const auto &I : RD->bases()) {
2630  auto *BaseDecl =
2631  cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
2632 
2633  // Ignore classes without a vtable.
2634  if (!BaseDecl->isDynamicClass())
2635  continue;
2636 
2637  CharUnits BaseOffset;
2638  CharUnits BaseOffsetFromNearestVBase;
2639  bool BaseDeclIsNonVirtualPrimaryBase;
2640 
2641  if (I.isVirtual()) {
2642  // Check if we've visited this virtual base before.
2643  if (!VBases.insert(BaseDecl).second)
2644  continue;
2645 
2646  const ASTRecordLayout &Layout =
2647  getContext().getASTRecordLayout(VTableClass);
2648 
2649  BaseOffset = Layout.getVBaseClassOffset(BaseDecl);
2650  BaseOffsetFromNearestVBase = CharUnits::Zero();
2651  BaseDeclIsNonVirtualPrimaryBase = false;
2652  } else {
2653  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
2654 
2655  BaseOffset = Base.getBaseOffset() + Layout.getBaseClassOffset(BaseDecl);
2656  BaseOffsetFromNearestVBase =
2657  OffsetFromNearestVBase + Layout.getBaseClassOffset(BaseDecl);
2658  BaseDeclIsNonVirtualPrimaryBase = Layout.getPrimaryBase() == BaseDecl;
2659  }
2660 
2662  BaseSubobject(BaseDecl, BaseOffset),
2663  I.isVirtual() ? BaseDecl : NearestVBase, BaseOffsetFromNearestVBase,
2664  BaseDeclIsNonVirtualPrimaryBase, VTableClass, VBases, Vptrs);
2665  }
2666 }
2667 
2669  // Ignore classes without a vtable.
2670  if (!RD->isDynamicClass())
2671  return;
2672 
2673  // Initialize the vtable pointers for this class and all of its bases.
2675  for (const VPtr &Vptr : getVTablePointers(RD))
2677 
2678  if (RD->getNumVBases())
2680 }
2681 
2683  llvm::Type *VTableTy,
2684  const CXXRecordDecl *RD) {
2685  Address VTablePtrSrc = Builder.CreateElementBitCast(This, VTableTy);
2686  llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
2687  TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTableTy);
2688  CGM.DecorateInstructionWithTBAA(VTable, TBAAInfo);
2689 
2690  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2691  CGM.getCodeGenOpts().StrictVTablePointers)
2693 
2694  return VTable;
2695 }
2696 
2697 // If a class has a single non-virtual base and does not introduce or override
2698 // virtual member functions or fields, it will have the same layout as its base.
2699 // This function returns the least derived such class.
2700 //
2701 // Casting an instance of a base class to such a derived class is technically
2702 // undefined behavior, but it is a relatively common hack for introducing member
2703 // functions on class instances with specific properties (e.g. llvm::Operator)
2704 // that works under most compilers and should not have security implications, so
2705 // we allow it by default. It can be disabled with -fsanitize=cfi-cast-strict.
2706 static const CXXRecordDecl *
2708  if (!RD->field_empty())
2709  return RD;
2710 
2711  if (RD->getNumVBases() != 0)
2712  return RD;
2713 
2714  if (RD->getNumBases() != 1)
2715  return RD;
2716 
2717  for (const CXXMethodDecl *MD : RD->methods()) {
2718  if (MD->isVirtual()) {
2719  // Virtual member functions are only ok if they are implicit destructors
2720  // because the implicit destructor will have the same semantics as the
2721  // base class's destructor if no fields are added.
2722  if (isa<CXXDestructorDecl>(MD) && MD->isImplicit())
2723  continue;
2724  return RD;
2725  }
2726  }
2727 
2729  RD->bases_begin()->getType()->getAsCXXRecordDecl());
2730 }
2731 
2733  llvm::Value *VTable,
2734  SourceLocation Loc) {
2735  if (SanOpts.has(SanitizerKind::CFIVCall))
2737  else if (CGM.getCodeGenOpts().WholeProgramVTables &&
2738  // Don't insert type test assumes if we are forcing public
2739  // visibility.
2741  QualType Ty = QualType(RD->getTypeForDecl(), 0);
2742  llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(Ty);
2743  llvm::Value *TypeId =
2744  llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD);
2745 
2746  llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy);
2747  // If we already know that the call has hidden LTO visibility, emit
2748  // @llvm.type.test(). Otherwise emit @llvm.public.type.test(), which WPD
2749  // will convert to @llvm.type.test() if we assert at link time that we have
2750  // whole program visibility.
2752  ? llvm::Intrinsic::type_test
2753  : llvm::Intrinsic::public_type_test;
2754  llvm::Value *TypeTest =
2755  Builder.CreateCall(CGM.getIntrinsic(IID), {CastedVTable, TypeId});
2756  Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
2757  }
2758 }
2759 
2761  llvm::Value *VTable,
2762  CFITypeCheckKind TCK,
2763  SourceLocation Loc) {
2764  if (!SanOpts.has(SanitizerKind::CFICastStrict))
2766 
2767  EmitVTablePtrCheck(RD, VTable, TCK, Loc);
2768 }
2769 
2771  bool MayBeNull,
2772  CFITypeCheckKind TCK,
2773  SourceLocation Loc) {
2774  if (!getLangOpts().CPlusPlus)
2775  return;
2776 
2777  auto *ClassTy = T->getAs<RecordType>();
2778  if (!ClassTy)
2779  return;
2780 
2781  const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(ClassTy->getDecl());
2782 
2783  if (!ClassDecl->isCompleteDefinition() || !ClassDecl->isDynamicClass())
2784  return;
2785 
2786  if (!SanOpts.has(SanitizerKind::CFICastStrict))
2787  ClassDecl = LeastDerivedClassWithSameLayout(ClassDecl);
2788 
2789  llvm::BasicBlock *ContBlock = nullptr;
2790 
2791  if (MayBeNull) {
2792  llvm::Value *DerivedNotNull =
2793  Builder.CreateIsNotNull(Derived.getPointer(), "cast.nonnull");
2794 
2795  llvm::BasicBlock *CheckBlock = createBasicBlock("cast.check");
2796  ContBlock = createBasicBlock("cast.cont");
2797 
2798  Builder.CreateCondBr(DerivedNotNull, CheckBlock, ContBlock);
2799 
2800  EmitBlock(CheckBlock);
2801  }
2802 
2803  llvm::Value *VTable;
2804  std::tie(VTable, ClassDecl) =
2805  CGM.getCXXABI().LoadVTablePtr(*this, Derived, ClassDecl);
2806 
2807  EmitVTablePtrCheck(ClassDecl, VTable, TCK, Loc);
2808 
2809  if (MayBeNull) {
2810  Builder.CreateBr(ContBlock);
2811  EmitBlock(ContBlock);
2812  }
2813 }
2814 
2816  llvm::Value *VTable,
2817  CFITypeCheckKind TCK,
2818  SourceLocation Loc) {
2819  if (!CGM.getCodeGenOpts().SanitizeCfiCrossDso &&
2821  return;
2822 
2823  SanitizerMask M;
2824  llvm::SanitizerStatKind SSK;
2825  switch (TCK) {
2826  case CFITCK_VCall:
2827  M = SanitizerKind::CFIVCall;
2828  SSK = llvm::SanStat_CFI_VCall;
2829  break;
2830  case CFITCK_NVCall:
2831  M = SanitizerKind::CFINVCall;
2832  SSK = llvm::SanStat_CFI_NVCall;
2833  break;
2834  case CFITCK_DerivedCast:
2835  M = SanitizerKind::CFIDerivedCast;
2836  SSK = llvm::SanStat_CFI_DerivedCast;
2837  break;
2838  case CFITCK_UnrelatedCast:
2839  M = SanitizerKind::CFIUnrelatedCast;
2840  SSK = llvm::SanStat_CFI_UnrelatedCast;
2841  break;
2842  case CFITCK_ICall:
2843  case CFITCK_NVMFCall:
2844  case CFITCK_VMFCall:
2845  llvm_unreachable("unexpected sanitizer kind");
2846  }
2847 
2849  if (getContext().getNoSanitizeList().containsType(M, TypeName))
2850  return;
2851 
2852  SanitizerScope SanScope(this);
2854 
2855  llvm::Metadata *MD =
2857  llvm::Value *TypeId = llvm::MetadataAsValue::get(getLLVMContext(), MD);
2858 
2859  llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy);
2860  llvm::Value *TypeTest = Builder.CreateCall(
2861  CGM.getIntrinsic(llvm::Intrinsic::type_test), {CastedVTable, TypeId});
2862 
2863  llvm::Constant *StaticData[] = {
2864  llvm::ConstantInt::get(Int8Ty, TCK),
2867  };
2868 
2869  auto CrossDsoTypeId = CGM.CreateCrossDsoCfiTypeId(MD);
2870  if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && CrossDsoTypeId) {
2871  EmitCfiSlowPathCheck(M, TypeTest, CrossDsoTypeId, CastedVTable, StaticData);
2872  return;
2873  }
2874 
2875  if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
2876  EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
2877  return;
2878  }
2879 
2880  llvm::Value *AllVtables = llvm::MetadataAsValue::get(
2881  CGM.getLLVMContext(),
2882  llvm::MDString::get(CGM.getLLVMContext(), "all-vtables"));
2883  llvm::Value *ValidVtable = Builder.CreateCall(
2884  CGM.getIntrinsic(llvm::Intrinsic::type_test), {CastedVTable, AllVtables});
2885  EmitCheck(std::make_pair(TypeTest, M), SanitizerHandler::CFICheckFail,
2886  StaticData, {CastedVTable, ValidVtable});
2887 }
2888 
2890  if (!CGM.getCodeGenOpts().WholeProgramVTables ||
2892  return false;
2893 
2894  if (CGM.getCodeGenOpts().VirtualFunctionElimination)
2895  return true;
2896 
2897  if (!SanOpts.has(SanitizerKind::CFIVCall) ||
2898  !CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall))
2899  return false;
2900 
2902  return !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall,
2903  TypeName);
2904 }
2905 
2907  const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy,
2908  uint64_t VTableByteOffset) {
2909  SanitizerScope SanScope(this);
2910 
2911  EmitSanitizerStatReport(llvm::SanStat_CFI_VCall);
2912 
2913  llvm::Metadata *MD =
2915  llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD);
2916 
2917  llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy);
2918  llvm::Value *CheckedLoad = Builder.CreateCall(
2919  CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
2920  {CastedVTable, llvm::ConstantInt::get(Int32Ty, VTableByteOffset),
2921  TypeId});
2922  llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
2923 
2925  if (SanOpts.has(SanitizerKind::CFIVCall) &&
2926  !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall,
2927  TypeName)) {
2928  EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
2929  SanitizerHandler::CFICheckFail, {}, {});
2930  }
2931 
2932  return Builder.CreateBitCast(Builder.CreateExtractValue(CheckedLoad, 0),
2933  VTableTy);
2934 }
2935 
2937  const CXXMethodDecl *callOperator,
2938  CallArgList &callArgs) {
2939  // Get the address of the call operator.
2940  const CGFunctionInfo &calleeFnInfo =
2941  CGM.getTypes().arrangeCXXMethodDeclaration(callOperator);
2942  llvm::Constant *calleePtr =
2943  CGM.GetAddrOfFunction(GlobalDecl(callOperator),
2944  CGM.getTypes().GetFunctionType(calleeFnInfo));
2945 
2946  // Prepare the return slot.
2947  const FunctionProtoType *FPT =
2948  callOperator->getType()->castAs<FunctionProtoType>();
2949  QualType resultType = FPT->getReturnType();
2950  ReturnValueSlot returnSlot;
2951  if (!resultType->isVoidType() &&
2952  calleeFnInfo.getReturnInfo().getKind() == ABIArgInfo::Indirect &&
2953  !hasScalarEvaluationKind(calleeFnInfo.getReturnType()))
2954  returnSlot =
2955  ReturnValueSlot(ReturnValue, resultType.isVolatileQualified(),
2956  /*IsUnused=*/false, /*IsExternallyDestructed=*/true);
2957 
2958  // We don't need to separately arrange the call arguments because
2959  // the call can't be variadic anyway --- it's impossible to forward
2960  // variadic arguments.
2961 
2962  // Now emit our call.
2963  auto callee = CGCallee::forDirect(calleePtr, GlobalDecl(callOperator));
2964  RValue RV = EmitCall(calleeFnInfo, callee, returnSlot, callArgs);
2965 
2966  // If necessary, copy the returned value into the slot.
2967  if (!resultType->isVoidType() && returnSlot.isNull()) {
2968  if (getLangOpts().ObjCAutoRefCount && resultType->isObjCRetainableType()) {
2970  }
2971  EmitReturnOfRValue(RV, resultType);
2972  } else
2974 }
2975 
2977  const BlockDecl *BD = BlockInfo->getBlockDecl();
2978  const VarDecl *variable = BD->capture_begin()->getVariable();
2979  const CXXRecordDecl *Lambda = variable->getType()->getAsCXXRecordDecl();
2980  const CXXMethodDecl *CallOp = Lambda->getLambdaCallOperator();
2981 
2982  if (CallOp->isVariadic()) {
2983  // FIXME: Making this work correctly is nasty because it requires either
2984  // cloning the body of the call operator or making the call operator
2985  // forward.
2986  CGM.ErrorUnsupported(CurCodeDecl, "lambda conversion to variadic function");
2987  return;
2988  }
2989 
2990  // Start building arguments for forwarding call
2991  CallArgList CallArgs;
2992 
2993  QualType ThisType = getContext().getPointerType(getContext().getRecordType(Lambda));
2994  Address ThisPtr = GetAddrOfBlockDecl(variable);
2995  CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType);
2996 
2997  // Add the rest of the parameters.
2998  for (auto *param : BD->parameters())
2999  EmitDelegateCallArg(CallArgs, param, param->getBeginLoc());
3000 
3001  assert(!Lambda->isGenericLambda() &&
3002  "generic lambda interconversion to block not implemented");
3003  EmitForwardingCallToLambda(CallOp, CallArgs);
3004 }
3005 
3007  const CXXRecordDecl *Lambda = MD->getParent();
3008 
3009  // Start building arguments for forwarding call
3010  CallArgList CallArgs;
3011 
3012  QualType LambdaType = getContext().getRecordType(Lambda);
3013  QualType ThisType = getContext().getPointerType(LambdaType);
3014  Address ThisPtr = CreateMemTemp(LambdaType, "unused.capture");
3015  CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType);
3016 
3017  // Add the rest of the parameters.
3018  for (auto *Param : MD->parameters())
3019  EmitDelegateCallArg(CallArgs, Param, Param->getBeginLoc());
3020 
3021  const CXXMethodDecl *CallOp = Lambda->getLambdaCallOperator();
3022  // For a generic lambda, find the corresponding call operator specialization
3023  // to which the call to the static-invoker shall be forwarded.
3024  if (Lambda->isGenericLambda()) {
3025  assert(MD->isFunctionTemplateSpecialization());
3027  FunctionTemplateDecl *CallOpTemplate = CallOp->getDescribedFunctionTemplate();
3028  void *InsertPos = nullptr;
3029  FunctionDecl *CorrespondingCallOpSpecialization =
3030  CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos);
3031  assert(CorrespondingCallOpSpecialization);
3032  CallOp = cast<CXXMethodDecl>(CorrespondingCallOpSpecialization);
3033  }
3034  EmitForwardingCallToLambda(CallOp, CallArgs);
3035 }
3036 
3038  if (MD->isVariadic()) {
3039  // FIXME: Making this work correctly is nasty because it requires either
3040  // cloning the body of the call operator or making the call operator forward.
3041  CGM.ErrorUnsupported(MD, "lambda conversion to variadic function");
3042  return;
3043  }
3044 
3046 }
clang::CodeGen::CodeGenFunction::EmitCfiSlowPathCheck
void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond, llvm::ConstantInt *TypeId, llvm::Value *Ptr, ArrayRef< llvm::Constant * > StaticArgs)
Emit a slow path cross-DSO CFI check which calls __cfi_slowpath if Cond if false.
Definition: CGExpr.cpp:3372
clang::CXXMethodDecl::getThisType
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2488
clang::CodeGen::CodeGenFunction::SanitizerScope
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
Definition: CodeGenFunction.h:524
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:210
clang::CodeGen::CodeGenFunction::EmitVTablePtrCheckForCall
void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
Definition: CGClass.cpp:2760
clang::GlobalDecl::getDtorType
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:110
clang::CodeGen::CodeGenFunction::destroyCXXObject
static Destroyer destroyCXXObject
Definition: CodeGenFunction.h:2912
clang::FunctionProtoType::param_type_begin
param_type_iterator param_type_begin() const
Definition: Type.h:4385
clang::CodeGen::CodeGenFunction::EmitComplexExprIntoLValue
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Definition: CGExprComplex.cpp:1300
clang::CodeGen::CGRecordLayout::getBitFieldInfo
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
Definition: CGRecordLayout.h:222
clang::CodeGen::CGBuilderTy::CreateMemCpy
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:312
clang::CodeGen::CodeGenFunction::EvaluationOrder::Default
@ Default
! No language constraints on evaluation order.
clang::CXXCtorInitializer::getAnyMember
FieldDecl * getAnyMember() const
Definition: DeclCXX.h:2350
clang::CodeGen::CodeGenTypeCache::SizeTy
llvm::IntegerType * SizeTy
Definition: CodeGenTypeCache.h:50
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::Dtor_Base
@ Dtor_Base
Base object dtor.
Definition: ABI.h:36
clang::CodeGen::CodeGenFunction::EmitTrapCall
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
Definition: CGExpr.cpp:3583
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2269
clang::CodeGen::CodeGenFunction::EmitLambdaStaticInvokeBody
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
Definition: CGClass.cpp:3037
clang::CodeGen::LValueBaseInfo
Definition: CGValue.h:154
clang::BlockDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4369
clang::CXXMethodDecl::getThisObjectType
QualType getThisObjectType() const
Return the type of the object pointed by this.
Definition: DeclCXX.cpp:2499
clang::ASTRecordLayout::getFieldOffset
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2436
clang::CXXBaseSpecifier::getType
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:245
clang::ASTContext::getTypeDeclType
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1583
clang::CXXMethodDecl::isCopyAssignmentOperator
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Definition: DeclCXX.cpp:2396
clang::CodeGen::CodeGenFunction::EmitNullInitialization
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Definition: CodeGenFunction.cpp:1967
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3466
clang::CodeGen::CodeGenFunction::LoadCXXThis
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
Definition: CodeGenFunction.h:2802
clang::CharUnits::alignmentOfArrayElement
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:207
clang::CodeGen::CodeGenFunction::EmitVTablePtrCheck
void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for RD using llvm....
Definition: CGClass.cpp:2815
clang::CodeGen::TEK_Aggregate
@ TEK_Aggregate
Definition: CodeGenFunction.h:109
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
clang::ASTContext::getCharWidth
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Definition: ASTContext.h:2306
clang::CodeGen::CodeGenModule::CreateRuntimeFunction
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
Definition: CodeGenModule.cpp:4207
clang::CXXCtorInitializer::getBaseClass
const Type * getBaseClass() const
If this is a base class initializer, returns the type of the base class.
Definition: DeclCXX.cpp:2569
clang::CXXRecordDecl::isEffectivelyFinal
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
Definition: DeclCXX.cpp:2057
clang::CodeGen::CodeGenFunction::sanitizePerformTypeCheck
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
Definition: CGExpr.cpp:668
clang::CodeGen::CodeGenModule::getItaniumVTableContext
ItaniumVTableContext & getItaniumVTableContext()
Definition: CodeGenModule.h:753
clang::CodeGen::CodeGenFunction::EmitCheckSourceLocation
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
Definition: CGExpr.cpp:3125
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:428
clang::CodeGen::ABIArgInfo::getKind
Kind getKind() const
Definition: CGFunctionInfo.h:295
clang::CodeGen::CodeGenFunction::EmitTrapCheck
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
Definition: CGExpr.cpp:3543
clang::RecordDecl::mayInsertExtraPadding
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:4814
CodeGenFunction.h
clang::CodeGen::CodeGenFunction::MakeNaturalAlignPointeeAddrLValue
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
Definition: CodeGenFunction.cpp:200
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::CodeGen::CodeGenFunction::EmitCall
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
Definition: CGCall.cpp:4726
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::CodeGen::CodeGenFunction::CurCodeDecl
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Definition: CodeGenFunction.h:322
clang::CodeGen::CGCXXABI::LoadVTablePtr
virtual std::pair< llvm::Value *, const CXXRecordDecl * > LoadVTablePtr(CodeGenFunction &CGF, Address This, const CXXRecordDecl *RD)=0
Load a vtable from This, an object of polymorphic type RD, or from one of its virtual bases if it doe...
clang::ItaniumVTableContext::isRelativeLayout
bool isRelativeLayout() const
Definition: VTableBuilder.h:437
clang::CXXConstructExpr::getNumArgs
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1615
clang::ConstantArrayType
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3058
clang::FieldDecl::isZeroSize
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:4310
clang::CodeGen::AggValueSlot::DoesNotNeedGCBarriers
@ DoesNotNeedGCBarriers
Definition: CGValue.h:554
clang::CodeGen::CodeGenFunction::EmitNounwindRuntimeCall
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
clang::CodeGen::Address::getAlignment
CharUnits getAlignment() const
Return the alignment of this pointer.
Definition: Address.h:120
clang::CodeGen::CodeGenModule::getDynamicOffsetAlignment
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, const CXXRecordDecl *Class, CharUnits ExpectedTargetAlign)
Given a class pointer with an actual known alignment, and the expected alignment of an object at a dy...
Definition: CGClass.cpp:89
clang::CodeGen::CodeGenModule::GetAddrOfFunction
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
Definition: CodeGenModule.cpp:4119
HasTrivialDestructorBody
static bool HasTrivialDestructorBody(ASTContext &Context, const CXXRecordDecl *BaseClassDecl, const CXXRecordDecl *MostDerivedClassDecl)
Definition: CGClass.cpp:1351
clang::CodeGen::CodeGenFunction::EmitSynthesizedCXXCopyCtorCall
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E)
Definition: CGClass.cpp:2392
llvm::SmallVector
Definition: LLVM.h:38
clang::RecordDecl::field_empty
bool field_empty() const
Definition: Decl.h:4217
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6662
clang::FunctionTemplateDecl::findSpecialization
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition: DeclTemplate.cpp:411
clang::CodeGen::CodeGenModule::HasHiddenLTOVisibility
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Definition: CGVTables.cpp:1228
clang::CodeGen::CodeGenFunction::CFITCK_VCall
@ CFITCK_VCall
Definition: CodeGenFunction.h:2297
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:341
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::CodeGen::CodeGenFunction::EmitDestructorBody
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
Definition: CGClass.cpp:1437
EmitLValueForAnyFieldInitialization
static void EmitLValueForAnyFieldInitialization(CodeGenFunction &CGF, CXXCtorInitializer *MemberInit, LValue &LHS)
Definition: CGClass.cpp:614
EvaluatedExprVisitor.h
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6831
clang::CodeGen::CodeGenFunction::emitArrayLength
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
Definition: CodeGenFunction.cpp:2068
CXXInheritance.h
clang::Stmt::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
clang::CXXConstructorDecl::isDelegatingConstructor
bool isDelegatingConstructor() const
Determine whether this constructor is a delegating constructor.
Definition: DeclCXX.h:2591
CGRecordLayout.h
clang::CharUnits::QuantityType
int64_t QuantityType
Definition: CharUnits.h:40
clang::CodeGen::CGCXXABI::NeedsVTTParameter
virtual bool NeedsVTTParameter(GlobalDecl GD)
Return whether the given global decl needs a VTT parameter.
Definition: CGCXXABI.cpp:322
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::TypeDecl::getTypeForDecl
const Type * getTypeForDecl() const
Definition: Decl.h:3257
clang::ASTContext::getTargetAddressSpace
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.cpp:12230
Attr.h
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2594
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:56
clang::ASTRecordLayout::getBaseClassOffset
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:249
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:155
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:722
clang::CodeGen::CodeGenModule::AlwaysHasLTOVisibilityPublic
bool AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD)
Returns whether the given record has public LTO visibility (regardless of -lto-whole-program-visibili...
Definition: CGVTables.cpp:1205
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::CodeGen::CGCXXABI::isVirtualOffsetNeededForVTableField
virtual bool isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF, CodeGenFunction::VPtr Vptr)=0
Checks if ABI requires extra virtual offset for vtable field.
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6984
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:773
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1274
clang::TargetCXXABI::isItaniumFamily
bool isItaniumFamily() const
Does this ABI generally fall into the Itanium family of ABIs?
Definition: TargetCXXABI.h:124
clang::Decl::isUsed
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:457
clang::CodeGen::CodeGenVTables::GetAddrOfVTT
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
Definition: CGVTT.cpp:101
clang::CXXCtorInitializer::isBaseInitializer
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2276
clang::CodeGen::CodeGenFunction::createBasicBlock
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Definition: CodeGenFunction.h:2428
clang::CodeGen::CodeGenModule::getMinimumClassObjectSize
CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD)
Returns the minimum object size for an object of the given class type (or a class derived from it).
Definition: CGClass.cpp:57
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:99
clang::CodeGen::CodeGenFunction::emitImplicitAssignmentOperatorBody
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
Definition: CGClass.cpp:1550
clang::ASTRecordLayout::getSize
CharUnits getSize() const
getSize - Get the record size in characters.
Definition: RecordLayout.h:193
clang::CodeGen::AggValueSlot::mayOverlap
Overlap_t mayOverlap() const
Definition: CGValue.h:643
TargetInfo.h
llvm::Optional
Definition: LLVM.h:40
llvm::SmallPtrSet
Definition: ASTContext.h:82
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2172
clang::Ctor_Base
@ Ctor_Base
Base object ctor.
Definition: ABI.h:26
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:723
clang::Ctor_Complete
@ Ctor_Complete
Complete object ctor.
Definition: ABI.h:25
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7180
clang::CXXRecordDecl::isGenericLambda
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1509
clang::FunctionDecl::getTemplateSpecializationArgs
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3932
clang::CodeGen::CodeGenFunction::EmitLambdaDelegatingInvokeBody
void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD)
Definition: CGClass.cpp:3006
clang::CodeGen::CodeGenFunction::HaveInsertPoint
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
Definition: CodeGenFunction.h:2469
clang::ASTRecordLayout::getPrimaryBase
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
Definition: RecordLayout.h:234
clang::CodeGen::CodeGenFunction::EmitLValueForField
LValue EmitLValueForField(LValue Base, const FieldDecl *Field)
Definition: CGExpr.cpp:4342
clang::CodeGen::CodeGenFunction::getDestroyer
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:2093
clang::CXXCtorInitializer::isAnyMemberInitializer
bool isAnyMemberInitializer() const
Definition: DeclCXX.h:2284
clang::CodeGen::EHCleanup
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
Definition: EHScopeStack.h:80
clang::CXXInheritedCtorInitExpr::getLocation
SourceLocation getLocation() const LLVM_READONLY
Definition: ExprCXX.h:1709
clang::CXXDestructorDecl::getOperatorDelete
const FunctionDecl * getOperatorDelete() const
Definition: DeclCXX.h:2736
clang::CharUnits::alignmentAtOffset
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:200
clang::CodeGen::CodeGenFunction::EmitDelegateCXXConstructorCall
void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, const FunctionArgList &Args, SourceLocation Loc)
Definition: CGClass.cpp:2419
clang::CodeGen::CodeGenFunction::EmitARCRetainAutoreleasedReturnValue
llvm::Value * EmitARCRetainAutoreleasedReturnValue(llvm::Value *value)
Retain the given object which is the result of a function call.
Definition: CGObjC.cpp:2440
clang::ento::Store
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition: StoreRef.h:27
clang::CodeGen::CodeGenFunction::EmitStmt
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=None)
EmitStmt - Emit the code for the statement.
Definition: CGStmt.cpp:53
clang::CodeGen::CodeGenModule::computeNonVirtualBaseClassOffset
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
Definition: CGClass.cpp:169
clang::ASTContext::toBits
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
Definition: ASTContext.cpp:2509
clang::CodeGen::CGFunctionInfo::getReturnType
CanQualType getReturnType() const
Definition: CGFunctionInfo.h:709
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::CXXCtorInitializer::getIndirectMember
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2358
clang::CodeGen::CodeGenFunction::EmitExprAsInit
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
EmitExprAsInit - Emits the code necessary to initialize a location in memory with the given initializ...
Definition: CGDecl.cpp:1935
clang::CodeGen::CGCXXABI::EmitDestructorCall
virtual void EmitDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)=0
Emit the destructor call.
clang::CodeGen::CodeGenFunction::EmitInitializerForField
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init)
Definition: CGClass.cpp:690
clang::CodeGen::CodeGenFunction::GetVTTParameter
llvm::Value * GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, bool Delegating)
GetVTTParameter - Return the VTT parameter that should be passed to a base constructor/destructor wit...
Definition: CGClass.cpp:460
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:283
clang::CXXCtorInitializer::isIndirectMemberInitializer
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2288
clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
Definition: CGExpr.cpp:2084
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:269
CGDebugInfo.h
CanSkipVTablePointerInitialization
static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor)
CanSkipVTablePointerInitialization - Check whether we need to initialize any vtable pointers before c...
Definition: CGClass.cpp:1414
clang::Dtor_Complete
@ Dtor_Complete
Complete object dtor.
Definition: ABI.h:35
clang::CodeGen::CodeGenTypes::ConvertType
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:401
clang::CXXRecordDecl::getLambdaCallOperator
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1540
clang::FunctionProtoType::isVariadic
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4349
clang::CXXMethodDecl::isMoveAssignmentOperator
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Definition: DeclCXX.cpp:2417
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1565
clang::CodeGen::CodeGenTypeCache::VoidPtrTy
llvm::PointerType * VoidPtrTy
Definition: CodeGenTypeCache.h:56
clang::CodeGen::CodeGenFunction::EmitCXXAggrConstructorCall
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization=false)
EmitCXXAggrConstructorCall - Emit a loop to call a particular constructor for each of several members...
Definition: CGClass.cpp:1982
clang::CodeGen::CodeGenFunction::EmitTypeMetadataCodeForVCall
void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, llvm::Value *VTable, SourceLocation Loc)
If whole-program virtual table optimization is enabled, emit an assumption that VTable is a member of...
Definition: CGClass.cpp:2732
clang::CXXCtorInitializer::getSourceLocation
SourceLocation getSourceLocation() const
Determine the source location of the initializer.
Definition: DeclCXX.cpp:2576
clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Definition: CodeGenFunction.h:2718
Offset
unsigned Offset
Definition: Format.cpp:2717
clang::CodeGen::CodeGenFunction::EmitCXXDestructorCall
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
Definition: CGClass.cpp:2505
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
EmitMemberInitializer
static void EmitMemberInitializer(CodeGenFunction &CGF, const CXXRecordDecl *ClassDecl, CXXCtorInitializer *MemberInit, const CXXConstructorDecl *Constructor, FunctionArgList &Args)
Definition: CGClass.cpp:628
clang::CodeGen::CodeGenFunction::ShouldEmitVTableTypeCheckedLoad
bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
Definition: CGClass.cpp:2889
clang::CodeGen::CodeGenFunction::getOverlapForFieldInit
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
Definition: CGExprAgg.cpp:2017
clang::CodeGen::CodeGenFunction::EmitSanitizerStatReport
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
Definition: CodeGenFunction.cpp:2606
CodeGenOptions.h
clang::Qualifiers::getAddressSpace
LangAS getAddressSpace() const
Definition: Type.h:378
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:357
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:1006
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6895
V
#define V(N, I)
Definition: ASTContext.h:3237
clang::BlockDecl::capture_begin
capture_const_iterator capture_begin() const
Definition: Decl.h:4412
clang::CodeGen::CodeGenFunction::RunCleanupsScope
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Definition: CodeGenFunction.h:872
min
__DEVICE__ int min(int __a, int __b)
Definition: __clang_cuda_math.h:197
clang::CodeGen::CodeGenFunction::BlockInfo
const CodeGen::CGBlockInfo * BlockInfo
Definition: CodeGenFunction.h:609
clang::CodeGen::CodeGenFunction::VPtr::NearestVBase
const CXXRecordDecl * NearestVBase
Definition: CodeGenFunction.h:2270
clang::CodeGen::TBAAAccessInfo
Definition: CodeGenTBAA.h:41
clang::CodeGen::CodeGenFunction::hasScalarEvaluationKind
static bool hasScalarEvaluationKind(QualType T)
Definition: CodeGenFunction.h:2419
clang::CodeGen::CGCXXABI::initializeHiddenVirtualInheritanceMembers
virtual void initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Emit the code to initialize hidden members required to handle virtual inheritance,...
Definition: CGCXXABI.h:314
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
clang::CodeGen::CodeGenModule::CreateMetadataIdentifierForType
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
Definition: CodeGenModule.cpp:6843
clang::CodeGen::CodeGenFunction::TCK_UpcastToVirtualBase
@ TCK_UpcastToVirtualBase
Checking the operand of a cast to a virtual base object.
Definition: CodeGenFunction.h:2979
clang::CXXCtorType
CXXCtorType
C++ constructor types.
Definition: ABI.h:24
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1410
clang::CodeGen::CodeGenFunction::EmitVTableTypeCheckedLoad
llvm::Value * EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, llvm::Type *VTableTy, uint64_t VTableByteOffset)
Emit a type checked load from the given vtable.
Definition: CGClass.cpp:2906
DeclTemplate.h
clang::SanitizerSet
Definition: Sanitizers.h:153
clang::CodeGen::AggValueSlot::IsSanitizerChecked
@ IsSanitizerChecked
Definition: CGValue.h:555
clang::CXXConstructExpr::arguments
arg_range arguments()
Definition: ExprCXX.h:1599
clang::CodeGen::EHScopeStack::Cleanup
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
clang::CodeGen::CodeGenModule::getVBaseAlignment
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
Definition: CGClass.cpp:74
clang::CodeGen::CGCXXABI::getVTableAddressPoint
virtual llvm::Constant * getVTableAddressPoint(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject.
clang::ASTContext::getAsConstantArrayType
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2726
clang::CodeGen::CodeGenFunction::emitDestroy
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
Definition: CGDecl.cpp:2194
clang::CXXRecordDecl::methods
method_range methods() const
Definition: DeclCXX.h:639
clang::FunctionDecl::isTrivial
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2261
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4283
clang::QualType::getAddressSpace
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6756
clang::CodeGen::LValue::isVolatileQualified
bool isVolatileQualified() const
Definition: CGValue.h:272
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3812
clang::CodeGen::CodeGenModule::getClassPointerAlignment
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:38
getRecordType
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType.
Definition: SemaDeclAttr.cpp:492
clang::CXXCtorInitializer::getInit
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2406
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
clang::CodeGen::CodeGenFunction::EmitVTableAssumptionLoad
void EmitVTableAssumptionLoad(const VPtr &vptr, Address This)
Emit assumption that vptr load == global vtable.
Definition: CGClass.cpp:2363
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::BaseSubobject
Definition: BaseSubobject.h:30
clang::CodeGen::CodeGenFunction::EmitCheck
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask >> Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
Definition: CGExpr.cpp:3260
clang::CodeGen::CGCXXABI::addImplicitConstructorArgs
AddedStructorArgCounts addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, CallArgList &Args)
Add any ABI-specific implicit arguments needed to call a constructor.
Definition: CGCXXABI.cpp:341
clang::CodeGen::EHScopeStack
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
Definition: EHScopeStack.h:94
clang::CodeGen::LValue::isBitField
bool isBitField() const
Definition: CGValue.h:267
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:731
clang::CodeGen::Address::getType
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:99
clang::ASTContext::getTypeInfoDataSizeInChars
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
Definition: ASTContext.cpp:1853
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::FunctionDecl::hasTrivialBody
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
Definition: Decl.cpp:3047
CGFunctionInfo.h
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3012
clang::CXXDtorType
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
clang::DeclaratorContext::Member
@ Member
clang::MemberPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2976
clang::CodeGen::TEK_Complex
@ TEK_Complex
Definition: CodeGenFunction.h:108
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3116
clang::CodeGen::CodeGenFunction::EmitTypeCheck
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
Definition: CGExpr.cpp:675
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::CodeGen::CodeGenFunction::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenFunction.h:2026
clang::CXXRecordDecl::getNumBases
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:591
clang::CodeGen::CGCXXABI::getVTableAddressPointInStructor
virtual llvm::Value * getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base, const CXXRecordDecl *NearestVBase)=0
Get the address point of the vtable for the given base subobject while building a constructor or a de...
canEmitDelegateCallArgs
static bool canEmitDelegateCallArgs(CodeGenFunction &CGF, const CXXConstructorDecl *Ctor, CXXCtorType Type, CallArgList &Args)
Definition: CGClass.cpp:2170
clang::CodeGen::CodeGenTypeCache::VoidTy
llvm::Type * VoidTy
void
Definition: CodeGenTypeCache.h:34
clang::CodeGen::CGCXXABI::AddedStructorArgCounts::Suffix
unsigned Suffix
Definition: CGCXXABI.h:347
clang::CodeGen::CodeGenFunction::pushRegularPartialArrayCleanup
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
Definition: CGDecl.cpp:2395
clang::ASTRecordLayout::getNonVirtualSize
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
Definition: RecordLayout.h:210
clang::CXXConstructorDecl::isCopyOrMoveConstructor
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Definition: DeclCXX.cpp:2690
clang::CodeGen::CodeGenModule::getTBAAVTablePtrAccessInfo
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table poi...
Definition: CodeGenModule.cpp:1009
clang::CodeGen::CGRecordLayout
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
Definition: CGRecordLayout.h:121
clang::CharUnits::One
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition: CharUnits.h:58
clang::index::SymbolKind::Field
@ Field
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2703
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
clang::CodeGen::CodeGenFunction::getCleanupKind
CleanupKind getCleanupKind(QualType::DestructionKind kind)
Definition: CodeGenFunction.h:2092
clang::Qualifiers::hasObjCLifetime
bool hasObjCLifetime() const
Definition: Type.h:351
clang::CodeGen::AggValueSlot::MayOverlap
@ MayOverlap
Definition: CGValue.h:553
clang::CodeGen::CodeGenFunction::needsEHCleanup
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
Definition: CodeGenFunction.h:2077
clang::CodeGen::CodeGenFunction::pushEHDestroy
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroy - Push the standard destructor for the given type as an EH-only cleanup.
Definition: CGDecl.cpp:2110
clang::TypeInfoChars::Width
CharUnits Width
Definition: ASTContext.h:194
clang::ASTContext::getRecordType
QualType getRecordType(const RecordDecl *Decl) const
Definition: ASTContext.cpp:4759
clang::CodeGen::CodeGenTypes::arrangeCXXMethodDeclaration
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
Definition: CGCall.cpp:292
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::CodeGen::CodeGenFunction::PushDestructorCleanup
void PushDestructorCleanup(QualType T, Address Addr)
PushDestructorCleanup - Push a cleanup to call the complete-object destructor of an object of the giv...
Definition: CGClass.cpp:2536
clang::CXXConstructorDecl::init_end
init_iterator init_end()
Retrieve an iterator past the last initializer.
Definition: DeclCXX.h:2544
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::CodeGen::CodeGenFunction::CreateIRTemp
Address CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
Definition: CGExpr.cpp:130
clang::CodeGen::CodeGenFunction::GetVTablePtr
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
Definition: CGClass.cpp:2682
clang::CodeGen::CodeGenFunction::EmitInheritedCXXConstructorCall
void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, bool ForVirtualBase, Address This, bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E)
Emit a call to a constructor inherited from a base class, passing the current constructor's arguments...
Definition: CGClass.cpp:2271
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:749
clang::CXXConstructExpr::getConstructor
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1539
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2528
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1760
clang::TagDecl::isUnion
bool isUnion() const
Definition: Decl.h:3629
clang::CodeGen::AggValueSlot::IsDestructed
@ IsDestructed
Definition: CGValue.h:551
clang::CXXRecordDecl::bases
base_class_range bases()
Definition: DeclCXX.h:597
clang::CXXCtorInitializer::isBaseVirtual
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2330
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:2027
clang::CodeGen::CGBitFieldInfo::StorageOffset
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
Definition: CGRecordLayout.h:81
clang::CodeGen::CGBuilderTy::CreateConstInBoundsByteGEP
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
Definition: CGBuilder.h:277
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1984
clang::CodeGen::CodeGenFunction::CFITypeCheckKind
CFITypeCheckKind
Definition: CodeGenFunction.h:2296
clang::MemberPointerType::getClass
const Type * getClass() const
Definition: Type.h:2990
clang::CodeGen::ABIArgInfo::Indirect
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
Definition: CGFunctionInfo.h:49
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
clang::CodeGen::CodeGenTypes::inheritingCtorHasParams
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
Definition: CGCall.cpp:309
clang::CodeGen::CodeGenFunction::incrementProfileCounter
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Definition: CodeGenFunction.h:1528
clang::CodeGen::Address
An aligned address.
Definition: Address.h:74
Base
clang::CodeGen::RValue::isComplex
bool isComplex() const
Definition: CGValue.h:55
clang::CXXInheritedCtorInitExpr
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1658
clang::CodeGen::CodeGenFunction::EmitVTableAssumptionLoads
void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This)
Emit assumption load for all bases.
Definition: CGClass.cpp:2384
isMemcpyEquivalentSpecialMember
static bool isMemcpyEquivalentSpecialMember(const CXXMethodDecl *D)
Definition: CGClass.cpp:597
clang::TagDecl::isCompleteDefinition
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3528
clang::CodeGen::CodeGenFunction::SanOpts
SanitizerSet SanOpts
Sanitizers enabled for this function.
Definition: CodeGenFunction.h:518
clang::CodeGen::CGBuilderTy::CreateGEP
Address CreateGEP(Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:264
clang::CodeGen::CodeGenFunction::getEvaluationKind
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Definition: CodeGenFunction.cpp:218
clang::CodeGen::CodeGenFunction::EvaluationOrder
EvaluationOrder
Definition: CodeGenFunction.h:4744
clang::CodeGen::CodeGenFunction::TCK_ConstructorCall
@ TCK_ConstructorCall
Checking the 'this' pointer for a constructor call.
Definition: CodeGenFunction.h:2967
clang::CodeGen::Address::getAddressSpace
unsigned getAddressSpace() const
Return the address space that this address resides in.
Definition: Address.h:110
clang::CodeGen::CodeGenFunction::EmitLambdaBlockInvokeBody
void EmitLambdaBlockInvokeBody()
Definition: CGClass.cpp:2976
clang::ast_matchers::arrayType
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
Definition: ASTMatchersInternal.cpp:1035
clang::CodeGen::CodeGenFunction::EmitConstructorBody
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
Definition: CGClass.cpp:838
clang::CodeGen::CodeGenFunction::TCK_Upcast
@ TCK_Upcast
Checking the operand of a cast to a base object.
Definition: CodeGenFunction.h:2976
clang::RecordDecl::isAnonymousStructOrUnion
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4056
clang::CodeGen::CodeGenFunction::VPtr::OffsetFromNearestVBase
CharUnits OffsetFromNearestVBase
Definition: CodeGenFunction.h:2271
clang::CXXRecordDecl::vbases
base_class_range vbases()
Definition: DeclCXX.h:614
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:576
clang::CodeGen::CodeGenFunction::GetAddrOfBlockDecl
Address GetAddrOfBlockDecl(const VarDecl *var)
Definition: CGBlocks.cpp:1247
clang::MemberExpr::getMemberDecl
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3252
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:130
clang::interp::Null
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1128
clang::CodeGen::CodeGenModule::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenModule.h:737
clang::CodeGen::CodeGenFunction::CurGD
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Definition: CodeGenFunction.h:345
CharUnits.h
clang::CodeGen::CodeGenFunction::EmitDeleteCall
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits())
Definition: CGExprCXX.cpp:1774
clang::ASTRecordLayout::getVBaseClassOffset
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:259
clang::CodeGen::CodeGenTypeCache::Int32Ty
llvm::IntegerType * Int32Ty
Definition: CodeGenTypeCache.h:37
EmitBaseInitializer
static void EmitBaseInitializer(CodeGenFunction &CGF, const CXXRecordDecl *ClassDecl, CXXCtorInitializer *BaseInit)
Definition: CGClass.cpp:555
clang::TemplateArgumentList::asArray
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:291
clang::CXXConstructorDecl::isDefaultConstructor
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition: DeclCXX.cpp:2670
clang::CodeGen::CodeGenModule::CreateCrossDsoCfiTypeId
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
Definition: CodeGenModule.cpp:1670
clang::CXXRecordDecl::isEmpty
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1150
clang::CodeGen::CodeGenTypes::getCGRecordLayout
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
Definition: CodeGenTypes.cpp:908
clang::CodeGen::CGBitFieldInfo
Structure with information about how a bitfield should be accessed.
Definition: CGRecordLayout.h:65
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
FieldHasTrivialDestructorBody
static bool FieldHasTrivialDestructorBody(ASTContext &Context, const FieldDecl *Field)
Definition: CGClass.cpp:1394
clang::FunctionDecl::isDestroyingOperatorDelete
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:3285
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1615
clang::FieldDecl::getFieldIndex
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:4343
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:734
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7453
clang::CodeGen::CGBuilderTy::CreateLaunderInvariantGroup
Address CreateLaunderInvariantGroup(Address Addr)
Definition: CGBuilder.h:371
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:797
clang::CodeGen::CGDebugInfo::setInlinedAt
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline scope.
Definition: CGDebugInfo.h:419
clang::ASTRecordLayout
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
clang::CodeGen::AggValueSlot::isSanitizerChecked
bool isSanitizerChecked() const
Definition: CGValue.h:647
isInitializerOfDynamicClass
static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit)
Definition: CGClass.cpp:1260
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::CodeGen::CodeGenFunction::getOverlapForBaseInit
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual)
Determine whether a base class initialization may overlap some other object.
Definition: CGExprAgg.cpp:2035
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:619
ApplyNonVirtualAndVirtualOffset
static Address ApplyNonVirtualAndVirtualOffset(CodeGenFunction &CGF, Address addr, CharUnits nonVirtualOffset, llvm::Value *virtualOffset, const CXXRecordDecl *derivedClass, const CXXRecordDecl *nearestVBase)
Definition: CGClass.cpp:247
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::CodeGen::LValue::isSimple
bool isSimple() const
Definition: CGValue.h:265
clang::CXXConstructorDecl::init_const_iterator
CXXCtorInitializer *const * init_const_iterator
Iterates through the member/base initializer list.
Definition: DeclCXX.h:2524
clang::CodeGen::CodeGenFunction::MakeNaturalAlignAddrLValue
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
Definition: CodeGenFunction.cpp:189
clang::CastExpr::path_const_iterator
const typedef CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3547
clang::CodeGen::CodeGenFunction::getTargetHooks
const TargetCodeGenInfo & getTargetHooks() const
Definition: CodeGenFunction.h:2028
clang::CodeGen::AggValueSlot::forAddr
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
Definition: CGValue.h:574
clang::CodeGen::CodeGenFunction::EmitDelegateCallArg
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
Definition: CGCall.cpp:3799
clang::QualType::isTriviallyCopyableType
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2469
clang::CodeGen::CodeGenFunction::CFITCK_NVMFCall
@ CFITCK_NVMFCall
Definition: CodeGenFunction.h:2302
clang::CodeGen::CGDebugInfo::getInlinedAt
llvm::MDNode * getInlinedAt() const
Definition: CGDebugInfo.h:422
clang::FieldDecl::isBitField
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3008
clang::CodeGen::CGCXXABI::doStructorsInitializeVPtrs
virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass)=0
Checks if ABI requires to initialize vptrs for given dynamic class.
clang::CodeGen::CodeGenFunction::VPtr::Base
BaseSubobject Base
Definition: CodeGenFunction.h:2269
clang::syntax::NodeRole::Size
@ Size
false
#define false
Definition: stdbool.h:22
clang::CodeGen::CodeGenFunction::ParamValue::forDirect
static ParamValue forDirect(llvm::Value *value)
Definition: CodeGenFunction.h:3147
clang::CodeGen::CodeGenFunction::EmitDelegatingCXXConstructorCall
void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, const FunctionArgList &Args)
Definition: CGClass.cpp:2476
clang::CXXRecordDecl::getNumVBases
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition: DeclCXX.h:612
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:93
clang::CodeGen::CodeGenModule::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenModule.cpp:1075
BaseInitializerUsesThis
static bool BaseInitializerUsesThis(ASTContext &C, const Expr *Init)
Definition: CGClass.cpp:549
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
LeastDerivedClassWithSameLayout
static const CXXRecordDecl * LeastDerivedClassWithSameLayout(const CXXRecordDecl *RD)
Definition: CGClass.cpp:2707
clang::CodeGen::CodeGenFunction::InitializeVTablePointer
void InitializeVTablePointer(const VPtr &vptr)
Initialize the vtable pointer of the given subobject.
Definition: CGClass.cpp:2546
clang::CodeGen::CodeGenTypeCache::PtrDiffTy
llvm::IntegerType * PtrDiffTy
Definition: CodeGenTypeCache.h:51
clang::CharUnits::isZero
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition: CharUnits.h:116
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:742
clang::ASTContext::getTagDeclType
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
Definition: ASTContext.cpp:5923
clang::CodeGen::CodeGenFunction::EmitParmDecl
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Definition: CGDecl.cpp:2445
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::CodeGen::AggValueSlot::IsNotAliased
@ IsNotAliased
Definition: CGValue.h:550
clang::CodeGen::CGCXXABI::AddedStructorArgCounts
Similar to AddedStructorArgs, but only notes the number of additional arguments.
Definition: CGCXXABI.h:345
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1923
clang::Expr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:329
clang::CodeGen::CodeGenModule::GetNonVirtualBaseClassOffset
llvm::Constant * GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd)
Returns the offset from a derived class to a class.
Definition: CGClass.cpp:197
clang::RecordDecl::fields
field_range fields() const
Definition: Decl.h:4209
clang::CodeGen::CodeGenFunction::EmitAsanPrologueOrEpilogue
void EmitAsanPrologueOrEpilogue(bool Prologue)
Definition: CGClass.cpp:776
clang::CodeGen::CGBlockInfo::getBlockDecl
const BlockDecl * getBlockDecl() const
Definition: CGBlocks.h:310
clang::CodeGen::CodeGenModule::getVTables
CodeGenVTables & getVTables()
Definition: CodeGenModule.h:751
Value
Value
Definition: UninitializedValues.cpp:103
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::CodeGen::CodeGenFunction::EmitAggExpr
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
Definition: CGExprAgg.cpp:1993
clang::CodeGen::CodeGenFunction::CFITCK_DerivedCast
@ CFITCK_DerivedCast
Definition: CodeGenFunction.h:2299
clang::CodeGen::CodeGenFunction::LexicalScope
Definition: CodeGenFunction.h:931
clang::CXXConstructorDecl::getInheritedConstructor
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
Definition: DeclCXX.h:2676
clang::CodeGen::CodeGenFunction::BuildFunctionArgList
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
Definition: CodeGenFunction.cpp:1290
clang::CodeGen::CGFunctionInfo::usesInAlloca
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
Definition: CGFunctionInfo.h:725
clang::CodeGen::CodeGenFunction::VPtr::VTableClass
const CXXRecordDecl * VTableClass
Definition: CodeGenFunction.h:2272
clang::CodeGen::AggValueSlot::forLValue
static AggValueSlot forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
Definition: CGValue.h:587
clang::CodeGen::CGCallee
All available information about a concrete callee.
Definition: CGCall.h:60
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:353
clang::QualType::isPODType
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2361
clang::CodeGen::CGFunctionInfo::getReturnInfo
ABIArgInfo & getReturnInfo()
Definition: CGFunctionInfo.h:711
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1275
clang::CodeGen::CodeGenFunction::getTypes
CodeGenTypes & getTypes() const
Definition: CodeGenFunction.h:1983
clang::CXXConstructorDecl::init_begin
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition: DeclCXX.h:2535
clang::CodeGen::AggValueSlot
An aggregate value slot.
Definition: CGValue.h:491
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:214
clang::Qualifiers::hasVolatile
bool hasVolatile() const
Definition: Type.h:274
clang::Dtor_Comdat
@ Dtor_Comdat
The COMDAT used for dtors.
Definition: ABI.h:37
clang::CodeGen::CodeGenFunction::EmitForwardingCallToLambda
void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, CallArgList &CallArgs)
Definition: CGClass.cpp:2936
clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
Definition: CGClass.cpp:2119
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:238
TargetBuiltins.h
clang::CodeGen::NormalAndEHCleanup
@ NormalAndEHCleanup
Definition: EHScopeStack.h:86
clang::NamedDecl::getQualifiedNameAsString
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1626
clang::CodeGen::CodeGenFunction::LoadCXXVTT
llvm::Value * LoadCXXVTT()
LoadCXXVTT - Load the VTT parameter to base constructors/destructors have virtual bases.
Definition: CodeGenFunction.h:2812
clang::CodeGen::CodeGenVTables::getSubVTTIndex
uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSubVTTIndex - Return the index of the sub-VTT for the base class of the given record decl.
Definition: CGVTT.cpp:126
clang::TargetCXXABI::hasConstructorVariants
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
Definition: TargetCXXABI.h:196
clang::CodeGen::Address::getElementType
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition: Address.h:104
clang::CodeGen::CodeGenFunction::MakeAddrLValue
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
Definition: CodeGenFunction.h:2490
clang::CXXRecordDecl::hasTrivialDestructor
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1323
clang::CodeGen::CodeGenModule::DecorateInstructionWithTBAA
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
Definition: CodeGenModule.cpp:1056
clang::CodeGen::CGBuilderTy::CreateElementBitCast
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
Definition: CGBuilder.h:168
clang::CodeGen::CodeGenFunction::EmitScalarExpr
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
Definition: CGExprScalar.cpp:5041
clang::CXXRecordDecl::getDestructor
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1917
clang::CodeGen::CodeGenFunction::EmitVTablePtrCheckForCast
void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull, CFITypeCheckKind TCK, SourceLocation Loc)
Derived is the presumed address of an object of type T after a cast.
Definition: CGClass.cpp:2770
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:81
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2960
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::AggValueSlot::Overlap_t
Overlap_t
Definition: CGValue.h:553
CGCXXABI.h
clang::CodeGen::CodeGenFunction::FnRetTy
QualType FnRetTy
Definition: CodeGenFunction.h:324
clang::CXXThisExpr
Represents the this expression in C++.
Definition: ExprCXX.h:1149
clang::CodeGen::CGCXXABI::EmitMemberDataPointerAddress
virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, Address Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
Calculate an l-value from an object and a data member pointer.
Definition: CGCXXABI.cpp:58
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:261
clang::interp::This
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1137
clang::DeclaratorContext::TypeName
@ TypeName
clang::CodeGen::TEK_Scalar
@ TEK_Scalar
Definition: CodeGenFunction.h:107
CGBlocks.h
clang::CodeGen::CodeGenFunction::CFITCK_NVCall
@ CFITCK_NVCall
Definition: CodeGenFunction.h:2298
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:325
clang::CodeGen::CleanupKind
CleanupKind
Definition: EHScopeStack.h:77
clang::UnaryOperator::getSubExpr
Expr * getSubExpr() const
Definition: Expr.h:2219
clang
Definition: CalledOnceCheck.h:17
clang::IndirectFieldDecl
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3184
clang::CXXCtorInitializer::getMember
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2344
clang::CodeGen::CGCXXABI::EmitCtorCompleteObjectHandler
virtual llvm::BasicBlock * EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, const CXXRecordDecl *RD)
Definition: CGCXXABI.cpp:299
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
clang::CodeGen::CodeGenFunction::EmitCallArgs
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
Definition: CGCall.cpp:4180
clang::ASTContext::toCharUnitsFromBits
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Definition: ASTContext.cpp:2504
clang::CodeGen::CodeGenFunction::EmitAggregateCopy
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
Definition: CGExprAgg.cpp:2056
clang::CodeGenOptions::SanitizeTrap
SanitizerSet SanitizeTrap
Set of sanitizer checks that trap rather than diagnose.
Definition: CodeGenOptions.h:359
clang::CodeGen::CodeGenFunction::EvaluationOrder::ForceLeftToRight
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::UnaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:2214
clang::CodeGen::AggValueSlot::getAddress
Address getAddress() const
Definition: CGValue.h:627
clang::CodeGen::CGCXXABI::canSpeculativelyEmitVTable
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it's possible to emit a vtable for RD, even though we do not know that the vtable h...
clang::CodeGen::CodeGenFunction::RunCleanupsScope::ForceCleanup
void ForceCleanup(std::initializer_list< llvm::Value ** > ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Definition: CodeGenFunction.h:917
clang::CodeGen::CodeGenTypeCache::IntPtrTy
llvm::IntegerType * IntPtrTy
Definition: CodeGenTypeCache.h:49
clang::CodeGen::CodeGenModule::getNaturalTypeAlignment
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
Definition: CodeGenModule.cpp:6945
clang::CXXRecordDecl::bases_begin
base_class_iterator bases_begin()
Definition: DeclCXX.h:604
clang::CodeGen::CodeGenFunction::ParamValue
Definition: CodeGenFunction.h:3140
clang::transformer::callArgs
RangeSelector callArgs(std::string ID)
Definition: RangeSelector.cpp:298
clang::CXXBaseSpecifier
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
clang::CXXRecordDecl::hasDefinition
bool hasDefinition() const
Definition: DeclCXX.h:550
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3940
clang::CodeGen::CGCXXABI::EmitInstanceFunctionProlog
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::ConstEvaluatedExprVisitor
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
Definition: EvaluatedExprVisitor.h:137
clang::CodeGen::CodeGenFunction::EnterCXXTryStmt
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
Definition: CGException.cpp:617
clang::ASTRecordLayout::getFieldCount
unsigned getFieldCount() const
getFieldCount - Get the number of fields in the layout.
Definition: RecordLayout.h:196
clang::CXXRecordDecl::isAbstract
bool isAbstract() const
Determine whether this class has a pure virtual function.
Definition: DeclCXX.h:1178
clang::CodeGen::AggValueSlot::getQualifiers
Qualifiers getQualifiers() const
Definition: CGValue.h:602
clang::GlobalDecl::getCtorType
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:105
clang::Dtor_Deleting
@ Dtor_Deleting
Deleting dtor.
Definition: ABI.h:34
clang::CodeGen::CodeGenFunction::getVTablePointers
VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass)
Definition: CGClass.cpp:2600
clang::CodeGen::CodeGenFunction::GetAddressOfBaseClass
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
Definition: CGClass.cpp:293
clang::CodeGen::CodeGenFunction::EmitInlinedInheritingCXXConstructorCall
void EmitInlinedInheritingCXXConstructorCall(const CXXConstructorDecl *Ctor, CXXCtorType CtorType, bool ForVirtualBase, bool Delegating, CallArgList &Args)
Emit a call to an inheriting constructor (that is, one that invokes a constructor inherited from a ba...
Definition: CGClass.cpp:2318
clang::CodeGen::CGCXXABI::AddedStructorArgCounts::Prefix
unsigned Prefix
Definition: CGCXXABI.h:346
clang::FunctionDecl::isVariadic
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3004
clang::CodeGen::RValue::isScalar
bool isScalar() const
Definition: CGValue.h:54
clang::ASTRecordLayout::getAlignment
CharUnits getAlignment() const
getAlignment - Get the record alignment in characters.
Definition: RecordLayout.h:182
clang::CodeGen::CodeGenFunction::Destroyer
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
Definition: CodeGenFunction.h:2036
clang::CompoundStmt::body
body_range body()
Definition: Stmt.h:1468
clang::SanitizerSet::set
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Definition: Sanitizers.h:164
clang::CodeGen::CGCXXABI::GetVirtualBaseClassOffset
virtual llvm::Value * GetVirtualBaseClassOffset(CodeGenFunction &CGF, Address This, const CXXRecordDecl *ClassDecl, const CXXRecordDecl *BaseClassDecl)=0
clang::CodeGen::CodeGenFunction::VPtr
Struct with all information about dynamic [sub]class needed to set vptr.
Definition: CodeGenFunction.h:2268
clang::ASTContext::getASTRecordLayout
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
Definition: RecordLayoutBuilder.cpp:3275
clang::NoSanitizeList::containsType
bool containsType(SanitizerMask Mask, StringRef MangledTypeName, StringRef Category=StringRef()) const
Definition: NoSanitizeList.cpp:35
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:103
clang::BaseSubobject::getBaseOffset
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
Definition: BaseSubobject.h:46
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3624
clang::CodeGen::CodeGenFunction::EmitCtorPrologue
void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, FunctionArgList &Args)
EmitCtorPrologue - This routine generates necessary code to initialize base classes and non-static da...
Definition: CGClass.cpp:1269
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3169
clang::CodeGen::CodeGenFunction::EmitLValue
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
Definition: CGExpr.cpp:1272
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6622
clang::CXXRecordDecl::isDynamicClass
bool isDynamicClass() const
Definition: DeclCXX.h:563
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4826
clang::ASTContext::getPointerType
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Definition: ASTContext.cpp:3341
clang::CodeGen::TargetCodeGenInfo::performAddrSpaceCast
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
Definition: TargetInfo.cpp:522
clang::CXXRecordDecl::isPolymorphic
bool isPolymorphic() const
Whether this class is polymorphic (C++ [class.virtual]), which means that the class contains or inher...
Definition: DeclCXX.h:1171
clang::TargetCXXABI::areArgsDestroyedLeftToRightInCallee
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee? This is a fundamental language change,...
Definition: TargetCXXABI.h:190
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::ASTContext::getTypeInfoInChars
TypeInfoChars getTypeInfoInChars(const Type *T) const
Definition: ASTContext.cpp:1889
clang::FunctionDecl::isFunctionTemplateSpecialization
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2784
clang::CXXConstructExpr::getArg
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1618
clang::CodeGen::CodeGenFunction::FieldConstructionScope
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
Definition: CodeGenFunction.h:1603
clang::CodeGen::CodeGenFunction::GetAddressOfDerivedClass
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
Definition: CGClass.cpp:401
clang::CodeGen::CodeGenFunction::ParamValue::forIndirect
static ParamValue forIndirect(Address addr)
Definition: CodeGenFunction.h:3150
clang::CodeGen::CodeGenFunction::GetAddressOfDirectBaseInCompleteClass
Address GetAddressOfDirectBaseInCompleteClass(Address Value, const CXXRecordDecl *Derived, const CXXRecordDecl *Base, bool BaseIsVirtual)
GetAddressOfBaseOfCompleteClass - Convert the given pointer to a complete class to the given direct b...
Definition: CGClass.cpp:219
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
clang::CodeGen::CallArg
Definition: CGCall.h:214
clang::FunctionDecl::getBuiltinID
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:3406
clang::CodeGen::CodeGenFunction::InlinedInheritingConstructorScope
Definition: CodeGenFunction.h:1663
clang::CodeGen::CodeGenFunction::CreateMemTemp
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Definition: CGExpr.cpp:135
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::CodeGenFunction::LoadCXXThisAddress
Address LoadCXXThisAddress()
Definition: CGClass.cpp:128
clang::IndirectFieldDecl::chain
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3206
clang::CodeGen::CodeGenModule::getAddrOfCXXStructor
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
Definition: CodeGenModule.h:1062
clang::CXXConstructExpr::isListInitialization
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1558
clang::FunctionDecl::getDescribedFunctionTemplate
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3802
clang::CodeGen::CodeGenFunction::IsConstructorDelegationValid
static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
Definition: CGClass.cpp:728
clang::CodeGen::ReturnValueSlot::isNull
bool isNull() const
Definition: CGCall.h:373
clang::CodeGen::CodeGenFunction::EmitBranchThroughCleanup
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
Definition: CGCleanup.cpp:1087
clang::QualType::isDestructedType
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1287
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::CXXCtorInitializer
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2207
clang::CodeGen::CodeGenModule::getIntrinsic
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
Definition: CodeGenModule.cpp:5487
clang::CodeGen::AggValueSlot::IsNotSanitizerChecked
@ IsNotSanitizerChecked
Definition: CGValue.h:555
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2571
clang::CodeGen::CodeGenModule::DecorateInstructionWithInvariantGroup
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, const CXXRecordDecl *RD)
Adds !invariant.barrier !tag to instruction.
Definition: CodeGenModule.cpp:1062
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::CodeGen::CodeGenFunction::EnterDtorCleanups
void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type)
EnterDtorCleanups - Enter the cleanups necessary to complete the given phase of destruction for a des...
Definition: CGClass.cpp:1844
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:259
clang::CodeGen::CodeGenTypes::arrangeCXXConstructorCall
const CGFunctionInfo & arrangeCXXConstructorCall(const CallArgList &Args, const CXXConstructorDecl *D, CXXCtorType CtorKind, unsigned ExtraPrefixArgs, unsigned ExtraSuffixArgs, bool PassProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
Definition: CGCall.cpp:403
clang::CodeGen::CodeGenFunction::CFITCK_UnrelatedCast
@ CFITCK_UnrelatedCast
Definition: CodeGenFunction.h:2300
clang::CodeGen::CodeGenFunction::EmitAggregateCopyCtor
void EmitAggregateCopyCtor(LValue Dest, LValue Src, AggValueSlot::Overlap_t MayOverlap)
Definition: CodeGenFunction.h:2701
clang::CodeGen::CodeGenFunction::CFITCK_VMFCall
@ CFITCK_VMFCall
Definition: CodeGenFunction.h:2303
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::CodeGen::AggValueSlot::IsNotZeroed
@ IsNotZeroed
Definition: CGValue.h:552
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2810
clang::ASTContext::getNoSanitizeList
const NoSanitizeList & getNoSanitizeList() const
Definition: ASTContext.h:801
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:563
StmtCXX.h
clang::CodeGen::CodeGenFunction::EmitLValueForFieldInitialization
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
Definition: CGExpr.cpp:4511
clang::CodeGen::CodeGenFunction::InitializeVTablePointers
void InitializeVTablePointers(const CXXRecordDecl *ClassDecl)
Definition: CGClass.cpp:2668
clang::CXXConstructExpr
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1467
clang::CodeGen::CodeGenFunction::ReturnBlock
JumpDest ReturnBlock
ReturnBlock - Unified return block.
Definition: CodeGenFunction.h:352
clang::CodeGen::CodeGenModule::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenModule.h:743
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:791
clang::CharUnits::isPositive
bool isPositive() const
isPositive - Test whether the quantity is greater than zero.
Definition: CharUnits.h:122
clang::CXXMemberCallExpr
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:177
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1997
clang::SanitizerMask
Definition: Sanitizers.h:30
clang::CXXMethodDecl::isVirtual
bool isVirtual() const
Definition: DeclCXX.h:2027
clang::CodeGen::ApplyInlineDebugLocation
A scoped helper to set the current debug location to an inlined location.
Definition: CGDebugInfo.h:852
clang::CodeGen::CodeGenFunction::EmitCXXMemberDataPointerAddress
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Emit the address of a field using a member data pointer.
Definition: CGClass.cpp:148
RecordLayout.h
clang::CodeGen::CodeGenFunction::CurFuncDecl
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Definition: CodeGenFunction.h:320
clang::CodeGen::RValue::getAggregateAddress
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
Definition: CGValue.h:73
clang::CodeGen::CodeGenFunction::EmitCheckTypeDescriptor
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
Definition: CGExpr.cpp:3044
clang::CodeGen::CodeGenFunction::ExitCXXTryStmt
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
Definition: CGException.cpp:1186
clang::CodeGen::CGBuilderTy::CreateLoad
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition: CGBuilder.h:71
clang::CodeGen::LValue::getBitFieldAddress
Address getBitFieldAddress() const
Definition: CGValue.h:390
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2098
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1983
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:356
clang::CodeGen::CodeGenFunction::CFITCK_ICall
@ CFITCK_ICall
Definition: CodeGenFunction.h:2301
clang::CodeGen::CGCXXABI::getSrcArgforCopyCtor
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, FunctionArgList &Args) const =0
clang::CodeGen::AggValueSlot::DoesNotOverlap
@ DoesNotOverlap
Definition: CGValue.h:553
clang::CXXDestructorDecl::getOperatorDeleteThisArg
Expr * getOperatorDeleteThisArg() const
Definition: DeclCXX.h:2740