clang  15.0.0git
CGExprCXX.cpp
Go to the documentation of this file.
1 //===--- CGExprCXX.cpp - Emit LLVM Code for C++ expressions ---------------===//
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 code generation of C++ expressions
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGCUDARuntime.h"
14 #include "CGCXXABI.h"
15 #include "CGDebugInfo.h"
16 #include "CGObjCRuntime.h"
17 #include "CodeGenFunction.h"
18 #include "ConstantEmitter.h"
19 #include "TargetInfo.h"
22 #include "llvm/IR/Intrinsics.h"
23 
24 using namespace clang;
25 using namespace CodeGen;
26 
27 namespace {
28 struct MemberCallInfo {
29  RequiredArgs ReqArgs;
30  // Number of prefix arguments for the call. Ignores the `this` pointer.
31  unsigned PrefixSize;
32 };
33 }
34 
35 static MemberCallInfo
37  llvm::Value *This, llvm::Value *ImplicitParam,
38  QualType ImplicitParamTy, const CallExpr *CE,
39  CallArgList &Args, CallArgList *RtlArgs) {
40  assert(CE == nullptr || isa<CXXMemberCallExpr>(CE) ||
41  isa<CXXOperatorCallExpr>(CE));
42  assert(MD->isInstance() &&
43  "Trying to emit a member or operator call expr on a static method!");
44 
45  // Push the this ptr.
46  const CXXRecordDecl *RD =
48  Args.add(RValue::get(This), CGF.getTypes().DeriveThisType(RD, MD));
49 
50  // If there is an implicit parameter (e.g. VTT), emit it.
51  if (ImplicitParam) {
52  Args.add(RValue::get(ImplicitParam), ImplicitParamTy);
53  }
54 
55  const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
56  RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size());
57  unsigned PrefixSize = Args.size() - 1;
58 
59  // And the rest of the call args.
60  if (RtlArgs) {
61  // Special case: if the caller emitted the arguments right-to-left already
62  // (prior to emitting the *this argument), we're done. This happens for
63  // assignment operators.
64  Args.addFrom(*RtlArgs);
65  } else if (CE) {
66  // Special case: skip first argument of CXXOperatorCall (it is "this").
67  unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;
68  CGF.EmitCallArgs(Args, FPT, drop_begin(CE->arguments(), ArgsToSkip),
69  CE->getDirectCallee());
70  } else {
71  assert(
72  FPT->getNumParams() == 0 &&
73  "No CallExpr specified for function with non-zero number of arguments");
74  }
75  return {required, PrefixSize};
76 }
77 
79  const CXXMethodDecl *MD, const CGCallee &Callee,
80  ReturnValueSlot ReturnValue,
81  llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy,
82  const CallExpr *CE, CallArgList *RtlArgs) {
83  const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
84  CallArgList Args;
85  MemberCallInfo CallInfo = commonEmitCXXMemberOrOperatorCall(
86  *this, MD, This, ImplicitParam, ImplicitParamTy, CE, Args, RtlArgs);
87  auto &FnInfo = CGM.getTypes().arrangeCXXMethodCall(
88  Args, FPT, CallInfo.ReqArgs, CallInfo.PrefixSize);
89  return EmitCall(FnInfo, Callee, ReturnValue, Args, nullptr,
90  CE && CE == MustTailCall,
91  CE ? CE->getExprLoc() : SourceLocation());
92 }
93 
95  GlobalDecl Dtor, const CGCallee &Callee, llvm::Value *This, QualType ThisTy,
96  llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE) {
97  const CXXMethodDecl *DtorDecl = cast<CXXMethodDecl>(Dtor.getDecl());
98 
99  assert(!ThisTy.isNull());
100  assert(ThisTy->getAsCXXRecordDecl() == DtorDecl->getParent() &&
101  "Pointer/Object mixup");
102 
103  LangAS SrcAS = ThisTy.getAddressSpace();
104  LangAS DstAS = DtorDecl->getMethodQualifiers().getAddressSpace();
105  if (SrcAS != DstAS) {
106  QualType DstTy = DtorDecl->getThisType();
107  llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy);
108  This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS,
109  NewType);
110  }
111 
112  CallArgList Args;
113  commonEmitCXXMemberOrOperatorCall(*this, DtorDecl, This, ImplicitParam,
114  ImplicitParamTy, CE, Args, nullptr);
115  return EmitCall(CGM.getTypes().arrangeCXXStructorDeclaration(Dtor), Callee,
116  ReturnValueSlot(), Args, nullptr, CE && CE == MustTailCall,
117  CE ? CE->getExprLoc() : SourceLocation{});
118 }
119 
121  const CXXPseudoDestructorExpr *E) {
122  QualType DestroyedType = E->getDestroyedType();
123  if (DestroyedType.hasStrongOrWeakObjCLifetime()) {
124  // Automatic Reference Counting:
125  // If the pseudo-expression names a retainable object with weak or
126  // strong lifetime, the object shall be released.
127  Expr *BaseExpr = E->getBase();
128  Address BaseValue = Address::invalid();
129  Qualifiers BaseQuals;
130 
131  // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
132  if (E->isArrow()) {
133  BaseValue = EmitPointerWithAlignment(BaseExpr);
134  const auto *PTy = BaseExpr->getType()->castAs<PointerType>();
135  BaseQuals = PTy->getPointeeType().getQualifiers();
136  } else {
137  LValue BaseLV = EmitLValue(BaseExpr);
138  BaseValue = BaseLV.getAddress(*this);
139  QualType BaseTy = BaseExpr->getType();
140  BaseQuals = BaseTy.getQualifiers();
141  }
142 
143  switch (DestroyedType.getObjCLifetime()) {
147  break;
148 
151  DestroyedType.isVolatileQualified()),
153  break;
154 
156  EmitARCDestroyWeak(BaseValue);
157  break;
158  }
159  } else {
160  // C++ [expr.pseudo]p1:
161  // The result shall only be used as the operand for the function call
162  // operator (), and the result of such a call has type void. The only
163  // effect is the evaluation of the postfix-expression before the dot or
164  // arrow.
165  EmitIgnoredExpr(E->getBase());
166  }
167 
168  return RValue::get(nullptr);
169 }
170 
171 static CXXRecordDecl *getCXXRecord(const Expr *E) {
172  QualType T = E->getType();
173  if (const PointerType *PTy = T->getAs<PointerType>())
174  T = PTy->getPointeeType();
175  const RecordType *Ty = T->castAs<RecordType>();
176  return cast<CXXRecordDecl>(Ty->getDecl());
177 }
178 
179 // Note: This function also emit constructor calls to support a MSVC
180 // extensions allowing explicit constructor function call.
182  ReturnValueSlot ReturnValue) {
183  const Expr *callee = CE->getCallee()->IgnoreParens();
184 
185  if (isa<BinaryOperator>(callee))
187 
188  const MemberExpr *ME = cast<MemberExpr>(callee);
189  const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl());
190 
191  if (MD->isStatic()) {
192  // The method is static, emit it as we would a regular call.
193  CGCallee callee =
195  return EmitCall(getContext().getPointerType(MD->getType()), callee, CE,
196  ReturnValue);
197  }
198 
199  bool HasQualifier = ME->hasQualifier();
200  NestedNameSpecifier *Qualifier = HasQualifier ? ME->getQualifier() : nullptr;
201  bool IsArrow = ME->isArrow();
202  const Expr *Base = ME->getBase();
203 
205  CE, MD, ReturnValue, HasQualifier, Qualifier, IsArrow, Base);
206 }
207 
209  const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue,
210  bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow,
211  const Expr *Base) {
212  assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE));
213 
214  // Compute the object pointer.
215  bool CanUseVirtualCall = MD->isVirtual() && !HasQualifier;
216 
217  const CXXMethodDecl *DevirtualizedMethod = nullptr;
218  if (CanUseVirtualCall &&
219  MD->getDevirtualizedMethod(Base, getLangOpts().AppleKext)) {
220  const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
221  DevirtualizedMethod = MD->getCorrespondingMethodInClass(BestDynamicDecl);
222  assert(DevirtualizedMethod);
223  const CXXRecordDecl *DevirtualizedClass = DevirtualizedMethod->getParent();
224  const Expr *Inner = Base->IgnoreParenBaseCasts();
225  if (DevirtualizedMethod->getReturnType().getCanonicalType() !=
227  // If the return types are not the same, this might be a case where more
228  // code needs to run to compensate for it. For example, the derived
229  // method might return a type that inherits form from the return
230  // type of MD and has a prefix.
231  // For now we just avoid devirtualizing these covariant cases.
232  DevirtualizedMethod = nullptr;
233  else if (getCXXRecord(Inner) == DevirtualizedClass)
234  // If the class of the Inner expression is where the dynamic method
235  // is defined, build the this pointer from it.
236  Base = Inner;
237  else if (getCXXRecord(Base) != DevirtualizedClass) {
238  // If the method is defined in a class that is not the best dynamic
239  // one or the one of the full expression, we would have to build
240  // a derived-to-base cast to compute the correct this pointer, but
241  // we don't have support for that yet, so do a virtual call.
242  DevirtualizedMethod = nullptr;
243  }
244  }
245 
246  bool TrivialForCodegen =
247  MD->isTrivial() || (MD->isDefaulted() && MD->getParent()->isUnion());
248  bool TrivialAssignment =
249  TrivialForCodegen &&
252 
253  // C++17 demands that we evaluate the RHS of a (possibly-compound) assignment
254  // operator before the LHS.
255  CallArgList RtlArgStorage;
256  CallArgList *RtlArgs = nullptr;
257  LValue TrivialAssignmentRHS;
258  if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(CE)) {
259  if (OCE->isAssignmentOp()) {
260  if (TrivialAssignment) {
261  TrivialAssignmentRHS = EmitLValue(CE->getArg(1));
262  } else {
263  RtlArgs = &RtlArgStorage;
264  EmitCallArgs(*RtlArgs, MD->getType()->castAs<FunctionProtoType>(),
265  drop_begin(CE->arguments(), 1), CE->getDirectCallee(),
266  /*ParamsToSkip*/0, EvaluationOrder::ForceRightToLeft);
267  }
268  }
269  }
270 
271  LValue This;
272  if (IsArrow) {
273  LValueBaseInfo BaseInfo;
274  TBAAAccessInfo TBAAInfo;
275  Address ThisValue = EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
276  This = MakeAddrLValue(ThisValue, Base->getType(), BaseInfo, TBAAInfo);
277  } else {
278  This = EmitLValue(Base);
279  }
280 
281  if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(MD)) {
282  // This is the MSVC p->Ctor::Ctor(...) extension. We assume that's
283  // constructing a new complete object of type Ctor.
284  assert(!RtlArgs);
285  assert(ReturnValue.isNull() && "Constructor shouldn't have return value");
286  CallArgList Args;
288  *this, Ctor, This.getPointer(*this), /*ImplicitParam=*/nullptr,
289  /*ImplicitParamTy=*/QualType(), CE, Args, nullptr);
290 
291  EmitCXXConstructorCall(Ctor, Ctor_Complete, /*ForVirtualBase=*/false,
292  /*Delegating=*/false, This.getAddress(*this), Args,
294  /*NewPointerIsChecked=*/false);
295  return RValue::get(nullptr);
296  }
297 
298  if (TrivialForCodegen) {
299  if (isa<CXXDestructorDecl>(MD))
300  return RValue::get(nullptr);
301 
302  if (TrivialAssignment) {
303  // We don't like to generate the trivial copy/move assignment operator
304  // when it isn't necessary; just produce the proper effect here.
305  // It's important that we use the result of EmitLValue here rather than
306  // emitting call arguments, in order to preserve TBAA information from
307  // the RHS.
308  LValue RHS = isa<CXXOperatorCallExpr>(CE)
309  ? TrivialAssignmentRHS
310  : EmitLValue(*CE->arg_begin());
311  EmitAggregateAssign(This, RHS, CE->getType());
312  return RValue::get(This.getPointer(*this));
313  }
314 
315  assert(MD->getParent()->mayInsertExtraPadding() &&
316  "unknown trivial member function");
317  }
318 
319  // Compute the function type we're calling.
320  const CXXMethodDecl *CalleeDecl =
321  DevirtualizedMethod ? DevirtualizedMethod : MD;
322  const CGFunctionInfo *FInfo = nullptr;
323  if (const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl))
325  GlobalDecl(Dtor, Dtor_Complete));
326  else
327  FInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(CalleeDecl);
328 
329  llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo);
330 
331  // C++11 [class.mfct.non-static]p2:
332  // If a non-static member function of a class X is called for an object that
333  // is not of type X, or of a type derived from X, the behavior is undefined.
334  SourceLocation CallLoc;
335  ASTContext &C = getContext();
336  if (CE)
337  CallLoc = CE->getExprLoc();
338 
339  SanitizerSet SkippedChecks;
340  if (const auto *CMCE = dyn_cast<CXXMemberCallExpr>(CE)) {
341  auto *IOA = CMCE->getImplicitObjectArgument();
342  bool IsImplicitObjectCXXThis = IsWrappedCXXThis(IOA);
343  if (IsImplicitObjectCXXThis)
344  SkippedChecks.set(SanitizerKind::Alignment, true);
345  if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA))
346  SkippedChecks.set(SanitizerKind::Null, true);
347  }
349  This.getPointer(*this),
350  C.getRecordType(CalleeDecl->getParent()),
351  /*Alignment=*/CharUnits::Zero(), SkippedChecks);
352 
353  // C++ [class.virtual]p12:
354  // Explicit qualification with the scope operator (5.1) suppresses the
355  // virtual call mechanism.
356  //
357  // We also don't emit a virtual call if the base expression has a record type
358  // because then we know what the type is.
359  bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
360 
361  if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl)) {
362  assert(CE->arg_begin() == CE->arg_end() &&
363  "Destructor shouldn't have explicit parameters");
364  assert(ReturnValue.isNull() && "Destructor shouldn't have return value");
365  if (UseVirtualCall) {
367  This.getAddress(*this),
368  cast<CXXMemberCallExpr>(CE));
369  } else {
370  GlobalDecl GD(Dtor, Dtor_Complete);
371  CGCallee Callee;
372  if (getLangOpts().AppleKext && Dtor->isVirtual() && HasQualifier)
373  Callee = BuildAppleKextVirtualCall(Dtor, Qualifier, Ty);
374  else if (!DevirtualizedMethod)
375  Callee =
376  CGCallee::forDirect(CGM.getAddrOfCXXStructor(GD, FInfo, Ty), GD);
377  else {
378  Callee = CGCallee::forDirect(CGM.GetAddrOfFunction(GD, Ty), GD);
379  }
380 
381  QualType ThisTy =
382  IsArrow ? Base->getType()->getPointeeType() : Base->getType();
383  EmitCXXDestructorCall(GD, Callee, This.getPointer(*this), ThisTy,
384  /*ImplicitParam=*/nullptr,
385  /*ImplicitParamTy=*/QualType(), CE);
386  }
387  return RValue::get(nullptr);
388  }
389 
390  // FIXME: Uses of 'MD' past this point need to be audited. We may need to use
391  // 'CalleeDecl' instead.
392 
393  CGCallee Callee;
394  if (UseVirtualCall) {
395  Callee = CGCallee::forVirtual(CE, MD, This.getAddress(*this), Ty);
396  } else {
397  if (SanOpts.has(SanitizerKind::CFINVCall) &&
398  MD->getParent()->isDynamicClass()) {
399  llvm::Value *VTable;
400  const CXXRecordDecl *RD;
401  std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr(
402  *this, This.getAddress(*this), CalleeDecl->getParent());
404  }
405 
406  if (getLangOpts().AppleKext && MD->isVirtual() && HasQualifier)
407  Callee = BuildAppleKextVirtualCall(MD, Qualifier, Ty);
408  else if (!DevirtualizedMethod)
409  Callee =
411  else {
412  Callee =
413  CGCallee::forDirect(CGM.GetAddrOfFunction(DevirtualizedMethod, Ty),
414  GlobalDecl(DevirtualizedMethod));
415  }
416  }
417 
418  if (MD->isVirtual()) {
419  Address NewThisAddr =
421  *this, CalleeDecl, This.getAddress(*this), UseVirtualCall);
422  This.setAddress(NewThisAddr);
423  }
424 
426  CalleeDecl, Callee, ReturnValue, This.getPointer(*this),
427  /*ImplicitParam=*/nullptr, QualType(), CE, RtlArgs);
428 }
429 
430 RValue
432  ReturnValueSlot ReturnValue) {
433  const BinaryOperator *BO =
434  cast<BinaryOperator>(E->getCallee()->IgnoreParens());
435  const Expr *BaseExpr = BO->getLHS();
436  const Expr *MemFnExpr = BO->getRHS();
437 
438  const auto *MPT = MemFnExpr->getType()->castAs<MemberPointerType>();
439  const auto *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>();
440  const auto *RD =
441  cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl());
442 
443  // Emit the 'this' pointer.
445  if (BO->getOpcode() == BO_PtrMemI)
446  This = EmitPointerWithAlignment(BaseExpr);
447  else
448  This = EmitLValue(BaseExpr).getAddress(*this);
449 
450  EmitTypeCheck(TCK_MemberCall, E->getExprLoc(), This.getPointer(),
451  QualType(MPT->getClass(), 0));
452 
453  // Get the member function pointer.
454  llvm::Value *MemFnPtr = EmitScalarExpr(MemFnExpr);
455 
456  // Ask the ABI to load the callee. Note that This is modified.
457  llvm::Value *ThisPtrForCall = nullptr;
458  CGCallee Callee =
460  ThisPtrForCall, MemFnPtr, MPT);
461 
462  CallArgList Args;
463 
464  QualType ThisType =
465  getContext().getPointerType(getContext().getTagDeclType(RD));
466 
467  // Push the this ptr.
468  Args.add(RValue::get(ThisPtrForCall), ThisType);
469 
470  RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, 1);
471 
472  // And the rest of the call args
473  EmitCallArgs(Args, FPT, E->arguments());
474  return EmitCall(CGM.getTypes().arrangeCXXMethodCall(Args, FPT, required,
475  /*PrefixSize=*/0),
476  Callee, ReturnValue, Args, nullptr, E == MustTailCall,
477  E->getExprLoc());
478 }
479 
480 RValue
482  const CXXMethodDecl *MD,
483  ReturnValueSlot ReturnValue) {
484  assert(MD->isInstance() &&
485  "Trying to emit a member call expr on a static method!");
487  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
488  /*IsArrow=*/false, E->getArg(0));
489 }
490 
492  ReturnValueSlot ReturnValue) {
494 }
495 
497  Address DestPtr,
498  const CXXRecordDecl *Base) {
499  if (Base->isEmpty())
500  return;
501 
502  DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty);
503 
504  const ASTRecordLayout &Layout = CGF.getContext().getASTRecordLayout(Base);
505  CharUnits NVSize = Layout.getNonVirtualSize();
506 
507  // We cannot simply zero-initialize the entire base sub-object if vbptrs are
508  // present, they are initialized by the most derived class before calling the
509  // constructor.
511  Stores.emplace_back(CharUnits::Zero(), NVSize);
512 
513  // Each store is split by the existence of a vbptr.
514  CharUnits VBPtrWidth = CGF.getPointerSize();
515  std::vector<CharUnits> VBPtrOffsets =
517  for (CharUnits VBPtrOffset : VBPtrOffsets) {
518  // Stop before we hit any virtual base pointers located in virtual bases.
519  if (VBPtrOffset >= NVSize)
520  break;
521  std::pair<CharUnits, CharUnits> LastStore = Stores.pop_back_val();
522  CharUnits LastStoreOffset = LastStore.first;
523  CharUnits LastStoreSize = LastStore.second;
524 
525  CharUnits SplitBeforeOffset = LastStoreOffset;
526  CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset;
527  assert(!SplitBeforeSize.isNegative() && "negative store size!");
528  if (!SplitBeforeSize.isZero())
529  Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize);
530 
531  CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth;
532  CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset;
533  assert(!SplitAfterSize.isNegative() && "negative store size!");
534  if (!SplitAfterSize.isZero())
535  Stores.emplace_back(SplitAfterOffset, SplitAfterSize);
536  }
537 
538  // If the type contains a pointer to data member we can't memset it to zero.
539  // Instead, create a null constant and copy it to the destination.
540  // TODO: there are other patterns besides zero that we can usefully memset,
541  // like -1, which happens to be the pattern used by member-pointers.
542  // TODO: isZeroInitializable can be over-conservative in the case where a
543  // virtual base contains a member pointer.
544  llvm::Constant *NullConstantForBase = CGF.CGM.EmitNullConstantForBase(Base);
545  if (!NullConstantForBase->isNullValue()) {
546  llvm::GlobalVariable *NullVariable = new llvm::GlobalVariable(
547  CGF.CGM.getModule(), NullConstantForBase->getType(),
548  /*isConstant=*/true, llvm::GlobalVariable::PrivateLinkage,
549  NullConstantForBase, Twine());
550 
551  CharUnits Align =
552  std::max(Layout.getNonVirtualAlignment(), DestPtr.getAlignment());
553  NullVariable->setAlignment(Align.getAsAlign());
554 
555  Address SrcPtr =
556  Address(CGF.EmitCastToVoidPtr(NullVariable), CGF.Int8Ty, Align);
557 
558  // Get and call the appropriate llvm.memcpy overload.
559  for (std::pair<CharUnits, CharUnits> Store : Stores) {
560  CharUnits StoreOffset = Store.first;
561  CharUnits StoreSize = Store.second;
562  llvm::Value *StoreSizeVal = CGF.CGM.getSize(StoreSize);
563  CGF.Builder.CreateMemCpy(
564  CGF.Builder.CreateConstInBoundsByteGEP(DestPtr, StoreOffset),
565  CGF.Builder.CreateConstInBoundsByteGEP(SrcPtr, StoreOffset),
566  StoreSizeVal);
567  }
568 
569  // Otherwise, just memset the whole thing to zero. This is legal
570  // because in LLVM, all default initializers (other than the ones we just
571  // handled above) are guaranteed to have a bit pattern of all zeros.
572  } else {
573  for (std::pair<CharUnits, CharUnits> Store : Stores) {
574  CharUnits StoreOffset = Store.first;
575  CharUnits StoreSize = Store.second;
576  llvm::Value *StoreSizeVal = CGF.CGM.getSize(StoreSize);
577  CGF.Builder.CreateMemSet(
578  CGF.Builder.CreateConstInBoundsByteGEP(DestPtr, StoreOffset),
579  CGF.Builder.getInt8(0), StoreSizeVal);
580  }
581  }
582 }
583 
584 void
586  AggValueSlot Dest) {
587  assert(!Dest.isIgnored() && "Must have a destination!");
588  const CXXConstructorDecl *CD = E->getConstructor();
589 
590  // If we require zero initialization before (or instead of) calling the
591  // constructor, as can be the case with a non-user-provided default
592  // constructor, emit the zero initialization now, unless destination is
593  // already zeroed.
594  if (E->requiresZeroInitialization() && !Dest.isZeroed()) {
595  switch (E->getConstructionKind()) {
599  break;
603  CD->getParent());
604  break;
605  }
606  }
607 
608  // If this is a call to a trivial default constructor, do nothing.
609  if (CD->isTrivial() && CD->isDefaultConstructor())
610  return;
611 
612  // Elide the constructor if we're constructing from a temporary.
613  if (getLangOpts().ElideConstructors && E->isElidable()) {
614  // FIXME: This only handles the simplest case, where the source object
615  // is passed directly as the first argument to the constructor.
616  // This should also handle stepping though implicit casts and
617  // conversion sequences which involve two steps, with a
618  // conversion operator followed by a converting constructor.
619  const Expr *SrcObj = E->getArg(0);
620  assert(SrcObj->isTemporaryObject(getContext(), CD->getParent()));
621  assert(
622  getContext().hasSameUnqualifiedType(E->getType(), SrcObj->getType()));
623  EmitAggExpr(SrcObj, Dest);
624  return;
625  }
626 
627  if (const ArrayType *arrayType
628  = getContext().getAsArrayType(E->getType())) {
630  Dest.isSanitizerChecked());
631  } else {
633  bool ForVirtualBase = false;
634  bool Delegating = false;
635 
636  switch (E->getConstructionKind()) {
638  // We should be emitting a constructor; GlobalDecl will assert this
639  Type = CurGD.getCtorType();
640  Delegating = true;
641  break;
642 
645  break;
646 
648  ForVirtualBase = true;
649  LLVM_FALLTHROUGH;
650 
652  Type = Ctor_Base;
653  }
654 
655  // Call the constructor.
656  EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating, Dest, E);
657  }
658 }
659 
661  const Expr *Exp) {
662  if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(Exp))
663  Exp = E->getSubExpr();
664  assert(isa<CXXConstructExpr>(Exp) &&
665  "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr");
666  const CXXConstructExpr* E = cast<CXXConstructExpr>(Exp);
667  const CXXConstructorDecl *CD = E->getConstructor();
668  RunCleanupsScope Scope(*this);
669 
670  // If we require zero initialization before (or instead of) calling the
671  // constructor, as can be the case with a non-user-provided default
672  // constructor, emit the zero initialization now.
673  // FIXME. Do I still need this for a copy ctor synthesis?
675  EmitNullInitialization(Dest, E->getType());
676 
677  assert(!getContext().getAsConstantArrayType(E->getType())
678  && "EmitSynthesizedCXXCopyCtor - Copied-in Array");
679  EmitSynthesizedCXXCopyCtorCall(CD, Dest, Src, E);
680 }
681 
683  const CXXNewExpr *E) {
684  if (!E->isArray())
685  return CharUnits::Zero();
686 
687  // No cookie is required if the operator new[] being used is the
688  // reserved placement operator new[].
690  return CharUnits::Zero();
691 
692  return CGF.CGM.getCXXABI().GetArrayCookieSize(E);
693 }
694 
695 static llvm::Value *EmitCXXNewAllocSize(CodeGenFunction &CGF,
696  const CXXNewExpr *e,
697  unsigned minElements,
698  llvm::Value *&numElements,
699  llvm::Value *&sizeWithoutCookie) {
701 
702  if (!e->isArray()) {
703  CharUnits typeSize = CGF.getContext().getTypeSizeInChars(type);
704  sizeWithoutCookie
705  = llvm::ConstantInt::get(CGF.SizeTy, typeSize.getQuantity());
706  return sizeWithoutCookie;
707  }
708 
709  // The width of size_t.
710  unsigned sizeWidth = CGF.SizeTy->getBitWidth();
711 
712  // Figure out the cookie size.
713  llvm::APInt cookieSize(sizeWidth,
714  CalculateCookiePadding(CGF, e).getQuantity());
715 
716  // Emit the array size expression.
717  // We multiply the size of all dimensions for NumElements.
718  // e.g for 'int[2][3]', ElemType is 'int' and NumElements is 6.
719  numElements =
721  if (!numElements)
722  numElements = CGF.EmitScalarExpr(*e->getArraySize());
723  assert(isa<llvm::IntegerType>(numElements->getType()));
724 
725  // The number of elements can be have an arbitrary integer type;
726  // essentially, we need to multiply it by a constant factor, add a
727  // cookie size, and verify that the result is representable as a
728  // size_t. That's just a gloss, though, and it's wrong in one
729  // important way: if the count is negative, it's an error even if
730  // the cookie size would bring the total size >= 0.
731  bool isSigned
732  = (*e->getArraySize())->getType()->isSignedIntegerOrEnumerationType();
733  llvm::IntegerType *numElementsType
734  = cast<llvm::IntegerType>(numElements->getType());
735  unsigned numElementsWidth = numElementsType->getBitWidth();
736 
737  // Compute the constant factor.
738  llvm::APInt arraySizeMultiplier(sizeWidth, 1);
739  while (const ConstantArrayType *CAT
741  type = CAT->getElementType();
742  arraySizeMultiplier *= CAT->getSize();
743  }
744 
745  CharUnits typeSize = CGF.getContext().getTypeSizeInChars(type);
746  llvm::APInt typeSizeMultiplier(sizeWidth, typeSize.getQuantity());
747  typeSizeMultiplier *= arraySizeMultiplier;
748 
749  // This will be a size_t.
750  llvm::Value *size;
751 
752  // If someone is doing 'new int[42]' there is no need to do a dynamic check.
753  // Don't bloat the -O0 code.
754  if (llvm::ConstantInt *numElementsC =
755  dyn_cast<llvm::ConstantInt>(numElements)) {
756  const llvm::APInt &count = numElementsC->getValue();
757 
758  bool hasAnyOverflow = false;
759 
760  // If 'count' was a negative number, it's an overflow.
761  if (isSigned && count.isNegative())
762  hasAnyOverflow = true;
763 
764  // We want to do all this arithmetic in size_t. If numElements is
765  // wider than that, check whether it's already too big, and if so,
766  // overflow.
767  else if (numElementsWidth > sizeWidth &&
768  numElementsWidth - sizeWidth > count.countLeadingZeros())
769  hasAnyOverflow = true;
770 
771  // Okay, compute a count at the right width.
772  llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth);
773 
774  // If there is a brace-initializer, we cannot allocate fewer elements than
775  // there are initializers. If we do, that's treated like an overflow.
776  if (adjustedCount.ult(minElements))
777  hasAnyOverflow = true;
778 
779  // Scale numElements by that. This might overflow, but we don't
780  // care because it only overflows if allocationSize does, too, and
781  // if that overflows then we shouldn't use this.
782  numElements = llvm::ConstantInt::get(CGF.SizeTy,
783  adjustedCount * arraySizeMultiplier);
784 
785  // Compute the size before cookie, and track whether it overflowed.
786  bool overflow;
787  llvm::APInt allocationSize
788  = adjustedCount.umul_ov(typeSizeMultiplier, overflow);
789  hasAnyOverflow |= overflow;
790 
791  // Add in the cookie, and check whether it's overflowed.
792  if (cookieSize != 0) {
793  // Save the current size without a cookie. This shouldn't be
794  // used if there was overflow.
795  sizeWithoutCookie = llvm::ConstantInt::get(CGF.SizeTy, allocationSize);
796 
797  allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
798  hasAnyOverflow |= overflow;
799  }
800 
801  // On overflow, produce a -1 so operator new will fail.
802  if (hasAnyOverflow) {
803  size = llvm::Constant::getAllOnesValue(CGF.SizeTy);
804  } else {
805  size = llvm::ConstantInt::get(CGF.SizeTy, allocationSize);
806  }
807 
808  // Otherwise, we might need to use the overflow intrinsics.
809  } else {
810  // There are up to five conditions we need to test for:
811  // 1) if isSigned, we need to check whether numElements is negative;
812  // 2) if numElementsWidth > sizeWidth, we need to check whether
813  // numElements is larger than something representable in size_t;
814  // 3) if minElements > 0, we need to check whether numElements is smaller
815  // than that.
816  // 4) we need to compute
817  // sizeWithoutCookie := numElements * typeSizeMultiplier
818  // and check whether it overflows; and
819  // 5) if we need a cookie, we need to compute
820  // size := sizeWithoutCookie + cookieSize
821  // and check whether it overflows.
822 
823  llvm::Value *hasOverflow = nullptr;
824 
825  // If numElementsWidth > sizeWidth, then one way or another, we're
826  // going to have to do a comparison for (2), and this happens to
827  // take care of (1), too.
828  if (numElementsWidth > sizeWidth) {
829  llvm::APInt threshold(numElementsWidth, 1);
830  threshold <<= sizeWidth;
831 
832  llvm::Value *thresholdV
833  = llvm::ConstantInt::get(numElementsType, threshold);
834 
835  hasOverflow = CGF.Builder.CreateICmpUGE(numElements, thresholdV);
836  numElements = CGF.Builder.CreateTrunc(numElements, CGF.SizeTy);
837 
838  // Otherwise, if we're signed, we want to sext up to size_t.
839  } else if (isSigned) {
840  if (numElementsWidth < sizeWidth)
841  numElements = CGF.Builder.CreateSExt(numElements, CGF.SizeTy);
842 
843  // If there's a non-1 type size multiplier, then we can do the
844  // signedness check at the same time as we do the multiply
845  // because a negative number times anything will cause an
846  // unsigned overflow. Otherwise, we have to do it here. But at least
847  // in this case, we can subsume the >= minElements check.
848  if (typeSizeMultiplier == 1)
849  hasOverflow = CGF.Builder.CreateICmpSLT(numElements,
850  llvm::ConstantInt::get(CGF.SizeTy, minElements));
851 
852  // Otherwise, zext up to size_t if necessary.
853  } else if (numElementsWidth < sizeWidth) {
854  numElements = CGF.Builder.CreateZExt(numElements, CGF.SizeTy);
855  }
856 
857  assert(numElements->getType() == CGF.SizeTy);
858 
859  if (minElements) {
860  // Don't allow allocation of fewer elements than we have initializers.
861  if (!hasOverflow) {
862  hasOverflow = CGF.Builder.CreateICmpULT(numElements,
863  llvm::ConstantInt::get(CGF.SizeTy, minElements));
864  } else if (numElementsWidth > sizeWidth) {
865  // The other existing overflow subsumes this check.
866  // We do an unsigned comparison, since any signed value < -1 is
867  // taken care of either above or below.
868  hasOverflow = CGF.Builder.CreateOr(hasOverflow,
869  CGF.Builder.CreateICmpULT(numElements,
870  llvm::ConstantInt::get(CGF.SizeTy, minElements)));
871  }
872  }
873 
874  size = numElements;
875 
876  // Multiply by the type size if necessary. This multiplier
877  // includes all the factors for nested arrays.
878  //
879  // This step also causes numElements to be scaled up by the
880  // nested-array factor if necessary. Overflow on this computation
881  // can be ignored because the result shouldn't be used if
882  // allocation fails.
883  if (typeSizeMultiplier != 1) {
884  llvm::Function *umul_with_overflow
885  = CGF.CGM.getIntrinsic(llvm::Intrinsic::umul_with_overflow, CGF.SizeTy);
886 
887  llvm::Value *tsmV =
888  llvm::ConstantInt::get(CGF.SizeTy, typeSizeMultiplier);
889  llvm::Value *result =
890  CGF.Builder.CreateCall(umul_with_overflow, {size, tsmV});
891 
892  llvm::Value *overflowed = CGF.Builder.CreateExtractValue(result, 1);
893  if (hasOverflow)
894  hasOverflow = CGF.Builder.CreateOr(hasOverflow, overflowed);
895  else
896  hasOverflow = overflowed;
897 
898  size = CGF.Builder.CreateExtractValue(result, 0);
899 
900  // Also scale up numElements by the array size multiplier.
901  if (arraySizeMultiplier != 1) {
902  // If the base element type size is 1, then we can re-use the
903  // multiply we just did.
904  if (typeSize.isOne()) {
905  assert(arraySizeMultiplier == typeSizeMultiplier);
906  numElements = size;
907 
908  // Otherwise we need a separate multiply.
909  } else {
910  llvm::Value *asmV =
911  llvm::ConstantInt::get(CGF.SizeTy, arraySizeMultiplier);
912  numElements = CGF.Builder.CreateMul(numElements, asmV);
913  }
914  }
915  } else {
916  // numElements doesn't need to be scaled.
917  assert(arraySizeMultiplier == 1);
918  }
919 
920  // Add in the cookie size if necessary.
921  if (cookieSize != 0) {
922  sizeWithoutCookie = size;
923 
924  llvm::Function *uadd_with_overflow
925  = CGF.CGM.getIntrinsic(llvm::Intrinsic::uadd_with_overflow, CGF.SizeTy);
926 
927  llvm::Value *cookieSizeV = llvm::ConstantInt::get(CGF.SizeTy, cookieSize);
928  llvm::Value *result =
929  CGF.Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV});
930 
931  llvm::Value *overflowed = CGF.Builder.CreateExtractValue(result, 1);
932  if (hasOverflow)
933  hasOverflow = CGF.Builder.CreateOr(hasOverflow, overflowed);
934  else
935  hasOverflow = overflowed;
936 
937  size = CGF.Builder.CreateExtractValue(result, 0);
938  }
939 
940  // If we had any possibility of dynamic overflow, make a select to
941  // overwrite 'size' with an all-ones value, which should cause
942  // operator new to throw.
943  if (hasOverflow)
944  size = CGF.Builder.CreateSelect(hasOverflow,
945  llvm::Constant::getAllOnesValue(CGF.SizeTy),
946  size);
947  }
948 
949  if (cookieSize == 0)
950  sizeWithoutCookie = size;
951  else
952  assert(sizeWithoutCookie && "didn't set sizeWithoutCookie?");
953 
954  return size;
955 }
956 
957 static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init,
958  QualType AllocType, Address NewPtr,
959  AggValueSlot::Overlap_t MayOverlap) {
960  // FIXME: Refactor with EmitExprAsInit.
961  switch (CGF.getEvaluationKind(AllocType)) {
962  case TEK_Scalar:
963  CGF.EmitScalarInit(Init, nullptr,
964  CGF.MakeAddrLValue(NewPtr, AllocType), false);
965  return;
966  case TEK_Complex:
967  CGF.EmitComplexExprIntoLValue(Init, CGF.MakeAddrLValue(NewPtr, AllocType),
968  /*isInit*/ true);
969  return;
970  case TEK_Aggregate: {
971  AggValueSlot Slot
972  = AggValueSlot::forAddr(NewPtr, AllocType.getQualifiers(),
976  MayOverlap, AggValueSlot::IsNotZeroed,
978  CGF.EmitAggExpr(Init, Slot);
979  return;
980  }
981  }
982  llvm_unreachable("bad evaluation kind");
983 }
984 
986  const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy,
987  Address BeginPtr, llvm::Value *NumElements,
988  llvm::Value *AllocSizeWithoutCookie) {
989  // If we have a type with trivial initialization and no initializer,
990  // there's nothing to do.
991  if (!E->hasInitializer())
992  return;
993 
994  Address CurPtr = BeginPtr;
995 
996  unsigned InitListElements = 0;
997 
998  const Expr *Init = E->getInitializer();
999  Address EndOfInit = Address::invalid();
1000  QualType::DestructionKind DtorKind = ElementType.isDestructedType();
1002  llvm::Instruction *CleanupDominator = nullptr;
1003 
1004  CharUnits ElementSize = getContext().getTypeSizeInChars(ElementType);
1005  CharUnits ElementAlign =
1006  BeginPtr.getAlignment().alignmentOfArrayElement(ElementSize);
1007 
1008  // Attempt to perform zero-initialization using memset.
1009  auto TryMemsetInitialization = [&]() -> bool {
1010  // FIXME: If the type is a pointer-to-data-member under the Itanium ABI,
1011  // we can initialize with a memset to -1.
1012  if (!CGM.getTypes().isZeroInitializable(ElementType))
1013  return false;
1014 
1015  // Optimization: since zero initialization will just set the memory
1016  // to all zeroes, generate a single memset to do it in one shot.
1017 
1018  // Subtract out the size of any elements we've already initialized.
1019  auto *RemainingSize = AllocSizeWithoutCookie;
1020  if (InitListElements) {
1021  // We know this can't overflow; we check this when doing the allocation.
1022  auto *InitializedSize = llvm::ConstantInt::get(
1023  RemainingSize->getType(),
1024  getContext().getTypeSizeInChars(ElementType).getQuantity() *
1025  InitListElements);
1026  RemainingSize = Builder.CreateSub(RemainingSize, InitializedSize);
1027  }
1028 
1029  // Create the memset.
1030  Builder.CreateMemSet(CurPtr, Builder.getInt8(0), RemainingSize, false);
1031  return true;
1032  };
1033 
1034  // If the initializer is an initializer list, first do the explicit elements.
1035  if (const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
1036  // Initializing from a (braced) string literal is a special case; the init
1037  // list element does not initialize a (single) array element.
1038  if (ILE->isStringLiteralInit()) {
1039  // Initialize the initial portion of length equal to that of the string
1040  // literal. The allocation must be for at least this much; we emitted a
1041  // check for that earlier.
1042  AggValueSlot Slot =
1043  AggValueSlot::forAddr(CurPtr, ElementType.getQualifiers(),
1050  EmitAggExpr(ILE->getInit(0), Slot);
1051 
1052  // Move past these elements.
1053  InitListElements =
1054  cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
1055  ->getSize().getZExtValue();
1057  CurPtr, InitListElements, "string.init.end");
1058 
1059  // Zero out the rest, if any remain.
1060  llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1061  if (!ConstNum || !ConstNum->equalsInt(InitListElements)) {
1062  bool OK = TryMemsetInitialization();
1063  (void)OK;
1064  assert(OK && "couldn't memset character type?");
1065  }
1066  return;
1067  }
1068 
1069  InitListElements = ILE->getNumInits();
1070 
1071  // If this is a multi-dimensional array new, we will initialize multiple
1072  // elements with each init list element.
1073  QualType AllocType = E->getAllocatedType();
1074  if (const ConstantArrayType *CAT = dyn_cast_or_null<ConstantArrayType>(
1075  AllocType->getAsArrayTypeUnsafe())) {
1076  ElementTy = ConvertTypeForMem(AllocType);
1077  CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy);
1078  InitListElements *= getContext().getConstantArrayElementCount(CAT);
1079  }
1080 
1081  // Enter a partial-destruction Cleanup if necessary.
1082  if (needsEHCleanup(DtorKind)) {
1083  // In principle we could tell the Cleanup where we are more
1084  // directly, but the control flow can get so varied here that it
1085  // would actually be quite complex. Therefore we go through an
1086  // alloca.
1087  EndOfInit = CreateTempAlloca(BeginPtr.getType(), getPointerAlign(),
1088  "array.init.end");
1089  CleanupDominator = Builder.CreateStore(BeginPtr.getPointer(), EndOfInit);
1090  pushIrregularPartialArrayCleanup(BeginPtr.getPointer(), EndOfInit,
1091  ElementType, ElementAlign,
1092  getDestroyer(DtorKind));
1093  Cleanup = EHStack.stable_begin();
1094  }
1095 
1096  CharUnits StartAlign = CurPtr.getAlignment();
1097  for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
1098  // Tell the cleanup that it needs to destroy up to this
1099  // element. TODO: some of these stores can be trivially
1100  // observed to be unnecessary.
1101  if (EndOfInit.isValid()) {
1102  auto FinishedPtr =
1103  Builder.CreateBitCast(CurPtr.getPointer(), BeginPtr.getType());
1104  Builder.CreateStore(FinishedPtr, EndOfInit);
1105  }
1106  // FIXME: If the last initializer is an incomplete initializer list for
1107  // an array, and we have an array filler, we can fold together the two
1108  // initialization loops.
1109  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
1110  ILE->getInit(i)->getType(), CurPtr,
1112  CurPtr = Address(Builder.CreateInBoundsGEP(
1113  CurPtr.getElementType(), CurPtr.getPointer(),
1114  Builder.getSize(1), "array.exp.next"),
1115  CurPtr.getElementType(),
1116  StartAlign.alignmentAtOffset((i + 1) * ElementSize));
1117  }
1118 
1119  // The remaining elements are filled with the array filler expression.
1120  Init = ILE->getArrayFiller();
1121 
1122  // Extract the initializer for the individual array elements by pulling
1123  // out the array filler from all the nested initializer lists. This avoids
1124  // generating a nested loop for the initialization.
1125  while (Init && Init->getType()->isConstantArrayType()) {
1126  auto *SubILE = dyn_cast<InitListExpr>(Init);
1127  if (!SubILE)
1128  break;
1129  assert(SubILE->getNumInits() == 0 && "explicit inits in array filler?");
1130  Init = SubILE->getArrayFiller();
1131  }
1132 
1133  // Switch back to initializing one base element at a time.
1134  CurPtr = Builder.CreateElementBitCast(CurPtr, BeginPtr.getElementType());
1135  }
1136 
1137  // If all elements have already been initialized, skip any further
1138  // initialization.
1139  llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1140  if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
1141  // If there was a Cleanup, deactivate it.
1142  if (CleanupDominator)
1143  DeactivateCleanupBlock(Cleanup, CleanupDominator);
1144  return;
1145  }
1146 
1147  assert(Init && "have trailing elements to initialize but no initializer");
1148 
1149  // If this is a constructor call, try to optimize it out, and failing that
1150  // emit a single loop to initialize all remaining elements.
1151  if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
1152  CXXConstructorDecl *Ctor = CCE->getConstructor();
1153  if (Ctor->isTrivial()) {
1154  // If new expression did not specify value-initialization, then there
1155  // is no initialization.
1156  if (!CCE->requiresZeroInitialization() || Ctor->getParent()->isEmpty())
1157  return;
1158 
1159  if (TryMemsetInitialization())
1160  return;
1161  }
1162 
1163  // Store the new Cleanup position for irregular Cleanups.
1164  //
1165  // FIXME: Share this cleanup with the constructor call emission rather than
1166  // having it create a cleanup of its own.
1167  if (EndOfInit.isValid())
1168  Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
1169 
1170  // Emit a constructor call loop to initialize the remaining elements.
1171  if (InitListElements)
1172  NumElements = Builder.CreateSub(
1173  NumElements,
1174  llvm::ConstantInt::get(NumElements->getType(), InitListElements));
1175  EmitCXXAggrConstructorCall(Ctor, NumElements, CurPtr, CCE,
1176  /*NewPointerIsChecked*/true,
1177  CCE->requiresZeroInitialization());
1178  return;
1179  }
1180 
1181  // If this is value-initialization, we can usually use memset.
1182  ImplicitValueInitExpr IVIE(ElementType);
1183  if (isa<ImplicitValueInitExpr>(Init)) {
1184  if (TryMemsetInitialization())
1185  return;
1186 
1187  // Switch to an ImplicitValueInitExpr for the element type. This handles
1188  // only one case: multidimensional array new of pointers to members. In
1189  // all other cases, we already have an initializer for the array element.
1190  Init = &IVIE;
1191  }
1192 
1193  // At this point we should have found an initializer for the individual
1194  // elements of the array.
1195  assert(getContext().hasSameUnqualifiedType(ElementType, Init->getType()) &&
1196  "got wrong type of element to initialize");
1197 
1198  // If we have an empty initializer list, we can usually use memset.
1199  if (auto *ILE = dyn_cast<InitListExpr>(Init))
1200  if (ILE->getNumInits() == 0 && TryMemsetInitialization())
1201  return;
1202 
1203  // If we have a struct whose every field is value-initialized, we can
1204  // usually use memset.
1205  if (auto *ILE = dyn_cast<InitListExpr>(Init)) {
1206  if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) {
1207  if (RType->getDecl()->isStruct()) {
1208  unsigned NumElements = 0;
1209  if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RType->getDecl()))
1210  NumElements = CXXRD->getNumBases();
1211  for (auto *Field : RType->getDecl()->fields())
1212  if (!Field->isUnnamedBitfield())
1213  ++NumElements;
1214  // FIXME: Recurse into nested InitListExprs.
1215  if (ILE->getNumInits() == NumElements)
1216  for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
1217  if (!isa<ImplicitValueInitExpr>(ILE->getInit(i)))
1218  --NumElements;
1219  if (ILE->getNumInits() == NumElements && TryMemsetInitialization())
1220  return;
1221  }
1222  }
1223  }
1224 
1225  // Create the loop blocks.
1226  llvm::BasicBlock *EntryBB = Builder.GetInsertBlock();
1227  llvm::BasicBlock *LoopBB = createBasicBlock("new.loop");
1228  llvm::BasicBlock *ContBB = createBasicBlock("new.loop.end");
1229 
1230  // Find the end of the array, hoisted out of the loop.
1231  llvm::Value *EndPtr =
1232  Builder.CreateInBoundsGEP(BeginPtr.getElementType(), BeginPtr.getPointer(),
1233  NumElements, "array.end");
1234 
1235  // If the number of elements isn't constant, we have to now check if there is
1236  // anything left to initialize.
1237  if (!ConstNum) {
1238  llvm::Value *IsEmpty =
1239  Builder.CreateICmpEQ(CurPtr.getPointer(), EndPtr, "array.isempty");
1240  Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
1241  }
1242 
1243  // Enter the loop.
1244  EmitBlock(LoopBB);
1245 
1246  // Set up the current-element phi.
1247  llvm::PHINode *CurPtrPhi =
1248  Builder.CreatePHI(CurPtr.getType(), 2, "array.cur");
1249  CurPtrPhi->addIncoming(CurPtr.getPointer(), EntryBB);
1250 
1251  CurPtr = Address(CurPtrPhi, CurPtr.getElementType(), ElementAlign);
1252 
1253  // Store the new Cleanup position for irregular Cleanups.
1254  if (EndOfInit.isValid())
1255  Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
1256 
1257  // Enter a partial-destruction Cleanup if necessary.
1258  if (!CleanupDominator && needsEHCleanup(DtorKind)) {
1260  ElementType, ElementAlign,
1261  getDestroyer(DtorKind));
1262  Cleanup = EHStack.stable_begin();
1263  CleanupDominator = Builder.CreateUnreachable();
1264  }
1265 
1266  // Emit the initializer into this element.
1267  StoreAnyExprIntoOneUnit(*this, Init, Init->getType(), CurPtr,
1269 
1270  // Leave the Cleanup if we entered one.
1271  if (CleanupDominator) {
1272  DeactivateCleanupBlock(Cleanup, CleanupDominator);
1273  CleanupDominator->eraseFromParent();
1274  }
1275 
1276  // Advance to the next element by adjusting the pointer type as necessary.
1277  llvm::Value *NextPtr =
1278  Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr.getPointer(), 1,
1279  "array.next");
1280 
1281  // Check whether we've gotten to the end of the array and, if so,
1282  // exit the loop.
1283  llvm::Value *IsEnd = Builder.CreateICmpEQ(NextPtr, EndPtr, "array.atend");
1284  Builder.CreateCondBr(IsEnd, ContBB, LoopBB);
1285  CurPtrPhi->addIncoming(NextPtr, Builder.GetInsertBlock());
1286 
1287  EmitBlock(ContBB);
1288 }
1289 
1290 static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E,
1291  QualType ElementType, llvm::Type *ElementTy,
1292  Address NewPtr, llvm::Value *NumElements,
1293  llvm::Value *AllocSizeWithoutCookie) {
1294  ApplyDebugLocation DL(CGF, E);
1295  if (E->isArray())
1296  CGF.EmitNewArrayInitializer(E, ElementType, ElementTy, NewPtr, NumElements,
1297  AllocSizeWithoutCookie);
1298  else if (const Expr *Init = E->getInitializer())
1299  StoreAnyExprIntoOneUnit(CGF, Init, E->getAllocatedType(), NewPtr,
1301 }
1302 
1303 /// Emit a call to an operator new or operator delete function, as implicitly
1304 /// created by new-expressions and delete-expressions.
1306  const FunctionDecl *CalleeDecl,
1307  const FunctionProtoType *CalleeType,
1308  const CallArgList &Args) {
1309  llvm::CallBase *CallOrInvoke;
1310  llvm::Constant *CalleePtr = CGF.CGM.GetAddrOfFunction(CalleeDecl);
1311  CGCallee Callee = CGCallee::forDirect(CalleePtr, GlobalDecl(CalleeDecl));
1312  RValue RV =
1314  Args, CalleeType, /*ChainCall=*/false),
1315  Callee, ReturnValueSlot(), Args, &CallOrInvoke);
1316 
1317  /// C++1y [expr.new]p10:
1318  /// [In a new-expression,] an implementation is allowed to omit a call
1319  /// to a replaceable global allocation function.
1320  ///
1321  /// We model such elidable calls with the 'builtin' attribute.
1322  llvm::Function *Fn = dyn_cast<llvm::Function>(CalleePtr);
1323  if (CalleeDecl->isReplaceableGlobalAllocationFunction() &&
1324  Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) {
1325  CallOrInvoke->addFnAttr(llvm::Attribute::Builtin);
1326  }
1327 
1328  return RV;
1329 }
1330 
1332  const CallExpr *TheCall,
1333  bool IsDelete) {
1334  CallArgList Args;
1335  EmitCallArgs(Args, Type, TheCall->arguments());
1336  // Find the allocation or deallocation function that we're calling.
1337  ASTContext &Ctx = getContext();
1339  .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
1340 
1341  for (auto *Decl : Ctx.getTranslationUnitDecl()->lookup(Name))
1342  if (auto *FD = dyn_cast<FunctionDecl>(Decl))
1343  if (Ctx.hasSameType(FD->getType(), QualType(Type, 0)))
1344  return EmitNewDeleteCall(*this, FD, Type, Args);
1345  llvm_unreachable("predeclared global operator new/delete is missing");
1346 }
1347 
1348 namespace {
1349 /// The parameters to pass to a usual operator delete.
1350 struct UsualDeleteParams {
1351  bool DestroyingDelete = false;
1352  bool Size = false;
1353  bool Alignment = false;
1354 };
1355 }
1356 
1357 static UsualDeleteParams getUsualDeleteParams(const FunctionDecl *FD) {
1358  UsualDeleteParams Params;
1359 
1360  const FunctionProtoType *FPT = FD->getType()->castAs<FunctionProtoType>();
1361  auto AI = FPT->param_type_begin(), AE = FPT->param_type_end();
1362 
1363  // The first argument is always a void*.
1364  ++AI;
1365 
1366  // The next parameter may be a std::destroying_delete_t.
1367  if (FD->isDestroyingOperatorDelete()) {
1368  Params.DestroyingDelete = true;
1369  assert(AI != AE);
1370  ++AI;
1371  }
1372 
1373  // Figure out what other parameters we should be implicitly passing.
1374  if (AI != AE && (*AI)->isIntegerType()) {
1375  Params.Size = true;
1376  ++AI;
1377  }
1378 
1379  if (AI != AE && (*AI)->isAlignValT()) {
1380  Params.Alignment = true;
1381  ++AI;
1382  }
1383 
1384  assert(AI == AE && "unexpected usual deallocation function parameter");
1385  return Params;
1386 }
1387 
1388 namespace {
1389  /// A cleanup to call the given 'operator delete' function upon abnormal
1390  /// exit from a new expression. Templated on a traits type that deals with
1391  /// ensuring that the arguments dominate the cleanup if necessary.
1392  template<typename Traits>
1393  class CallDeleteDuringNew final : public EHScopeStack::Cleanup {
1394  /// Type used to hold llvm::Value*s.
1395  typedef typename Traits::ValueTy ValueTy;
1396  /// Type used to hold RValues.
1397  typedef typename Traits::RValueTy RValueTy;
1398  struct PlacementArg {
1399  RValueTy ArgValue;
1400  QualType ArgType;
1401  };
1402 
1403  unsigned NumPlacementArgs : 31;
1404  unsigned PassAlignmentToPlacementDelete : 1;
1405  const FunctionDecl *OperatorDelete;
1406  ValueTy Ptr;
1407  ValueTy AllocSize;
1408  CharUnits AllocAlign;
1409 
1410  PlacementArg *getPlacementArgs() {
1411  return reinterpret_cast<PlacementArg *>(this + 1);
1412  }
1413 
1414  public:
1415  static size_t getExtraSize(size_t NumPlacementArgs) {
1416  return NumPlacementArgs * sizeof(PlacementArg);
1417  }
1418 
1419  CallDeleteDuringNew(size_t NumPlacementArgs,
1420  const FunctionDecl *OperatorDelete, ValueTy Ptr,
1421  ValueTy AllocSize, bool PassAlignmentToPlacementDelete,
1422  CharUnits AllocAlign)
1423  : NumPlacementArgs(NumPlacementArgs),
1424  PassAlignmentToPlacementDelete(PassAlignmentToPlacementDelete),
1425  OperatorDelete(OperatorDelete), Ptr(Ptr), AllocSize(AllocSize),
1426  AllocAlign(AllocAlign) {}
1427 
1428  void setPlacementArg(unsigned I, RValueTy Arg, QualType Type) {
1429  assert(I < NumPlacementArgs && "index out of range");
1430  getPlacementArgs()[I] = {Arg, Type};
1431  }
1432 
1433  void Emit(CodeGenFunction &CGF, Flags flags) override {
1434  const auto *FPT = OperatorDelete->getType()->castAs<FunctionProtoType>();
1435  CallArgList DeleteArgs;
1436 
1437  // The first argument is always a void* (or C* for a destroying operator
1438  // delete for class type C).
1439  DeleteArgs.add(Traits::get(CGF, Ptr), FPT->getParamType(0));
1440 
1441  // Figure out what other parameters we should be implicitly passing.
1442  UsualDeleteParams Params;
1443  if (NumPlacementArgs) {
1444  // A placement deallocation function is implicitly passed an alignment
1445  // if the placement allocation function was, but is never passed a size.
1446  Params.Alignment = PassAlignmentToPlacementDelete;
1447  } else {
1448  // For a non-placement new-expression, 'operator delete' can take a
1449  // size and/or an alignment if it has the right parameters.
1450  Params = getUsualDeleteParams(OperatorDelete);
1451  }
1452 
1453  assert(!Params.DestroyingDelete &&
1454  "should not call destroying delete in a new-expression");
1455 
1456  // The second argument can be a std::size_t (for non-placement delete).
1457  if (Params.Size)
1458  DeleteArgs.add(Traits::get(CGF, AllocSize),
1459  CGF.getContext().getSizeType());
1460 
1461  // The next (second or third) argument can be a std::align_val_t, which
1462  // is an enum whose underlying type is std::size_t.
1463  // FIXME: Use the right type as the parameter type. Note that in a call
1464  // to operator delete(size_t, ...), we may not have it available.
1465  if (Params.Alignment)
1466  DeleteArgs.add(RValue::get(llvm::ConstantInt::get(
1467  CGF.SizeTy, AllocAlign.getQuantity())),
1468  CGF.getContext().getSizeType());
1469 
1470  // Pass the rest of the arguments, which must match exactly.
1471  for (unsigned I = 0; I != NumPlacementArgs; ++I) {
1472  auto Arg = getPlacementArgs()[I];
1473  DeleteArgs.add(Traits::get(CGF, Arg.ArgValue), Arg.ArgType);
1474  }
1475 
1476  // Call 'operator delete'.
1477  EmitNewDeleteCall(CGF, OperatorDelete, FPT, DeleteArgs);
1478  }
1479  };
1480 }
1481 
1482 /// Enter a cleanup to call 'operator delete' if the initializer in a
1483 /// new-expression throws.
1485  const CXXNewExpr *E,
1486  Address NewPtr,
1487  llvm::Value *AllocSize,
1488  CharUnits AllocAlign,
1489  const CallArgList &NewArgs) {
1490  unsigned NumNonPlacementArgs = E->passAlignment() ? 2 : 1;
1491 
1492  // If we're not inside a conditional branch, then the cleanup will
1493  // dominate and we can do the easier (and more efficient) thing.
1494  if (!CGF.isInConditionalBranch()) {
1495  struct DirectCleanupTraits {
1496  typedef llvm::Value *ValueTy;
1497  typedef RValue RValueTy;
1498  static RValue get(CodeGenFunction &, ValueTy V) { return RValue::get(V); }
1499  static RValue get(CodeGenFunction &, RValueTy V) { return V; }
1500  };
1501 
1502  typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;
1503 
1504  DirectCleanup *Cleanup = CGF.EHStack
1505  .pushCleanupWithExtra<DirectCleanup>(EHCleanup,
1506  E->getNumPlacementArgs(),
1507  E->getOperatorDelete(),
1508  NewPtr.getPointer(),
1509  AllocSize,
1510  E->passAlignment(),
1511  AllocAlign);
1512  for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
1513  auto &Arg = NewArgs[I + NumNonPlacementArgs];
1514  Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);
1515  }
1516 
1517  return;
1518  }
1519 
1520  // Otherwise, we need to save all this stuff.
1523  DominatingValue<RValue>::saved_type SavedAllocSize =
1524  DominatingValue<RValue>::save(CGF, RValue::get(AllocSize));
1525 
1526  struct ConditionalCleanupTraits {
1527  typedef DominatingValue<RValue>::saved_type ValueTy;
1528  typedef DominatingValue<RValue>::saved_type RValueTy;
1529  static RValue get(CodeGenFunction &CGF, ValueTy V) {
1530  return V.restore(CGF);
1531  }
1532  };
1533  typedef CallDeleteDuringNew<ConditionalCleanupTraits> ConditionalCleanup;
1534 
1535  ConditionalCleanup *Cleanup = CGF.EHStack
1536  .pushCleanupWithExtra<ConditionalCleanup>(EHCleanup,
1537  E->getNumPlacementArgs(),
1538  E->getOperatorDelete(),
1539  SavedNewPtr,
1540  SavedAllocSize,
1541  E->passAlignment(),
1542  AllocAlign);
1543  for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
1544  auto &Arg = NewArgs[I + NumNonPlacementArgs];
1545  Cleanup->setPlacementArg(
1546  I, DominatingValue<RValue>::save(CGF, Arg.getRValue(CGF)), Arg.Ty);
1547  }
1548 
1549  CGF.initFullExprCleanup();
1550 }
1551 
1553  // The element type being allocated.
1555 
1556  // 1. Build a call to the allocation function.
1557  FunctionDecl *allocator = E->getOperatorNew();
1558 
1559  // If there is a brace-initializer, cannot allocate fewer elements than inits.
1560  unsigned minElements = 0;
1561  if (E->isArray() && E->hasInitializer()) {
1562  const InitListExpr *ILE = dyn_cast<InitListExpr>(E->getInitializer());
1563  if (ILE && ILE->isStringLiteralInit())
1564  minElements =
1565  cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
1566  ->getSize().getZExtValue();
1567  else if (ILE)
1568  minElements = ILE->getNumInits();
1569  }
1570 
1571  llvm::Value *numElements = nullptr;
1572  llvm::Value *allocSizeWithoutCookie = nullptr;
1573  llvm::Value *allocSize =
1574  EmitCXXNewAllocSize(*this, E, minElements, numElements,
1575  allocSizeWithoutCookie);
1576  CharUnits allocAlign = getContext().getTypeAlignInChars(allocType);
1577 
1578  // Emit the allocation call. If the allocator is a global placement
1579  // operator, just "inline" it directly.
1580  Address allocation = Address::invalid();
1581  CallArgList allocatorArgs;
1582  if (allocator->isReservedGlobalPlacementOperator()) {
1583  assert(E->getNumPlacementArgs() == 1);
1584  const Expr *arg = *E->placement_arguments().begin();
1585 
1586  LValueBaseInfo BaseInfo;
1587  allocation = EmitPointerWithAlignment(arg, &BaseInfo);
1588 
1589  // The pointer expression will, in many cases, be an opaque void*.
1590  // In these cases, discard the computed alignment and use the
1591  // formal alignment of the allocated type.
1592  if (BaseInfo.getAlignmentSource() != AlignmentSource::Decl)
1593  allocation = allocation.withAlignment(allocAlign);
1594 
1595  // Set up allocatorArgs for the call to operator delete if it's not
1596  // the reserved global operator.
1597  if (E->getOperatorDelete() &&
1599  allocatorArgs.add(RValue::get(allocSize), getContext().getSizeType());
1600  allocatorArgs.add(RValue::get(allocation.getPointer()), arg->getType());
1601  }
1602 
1603  } else {
1604  const FunctionProtoType *allocatorType =
1605  allocator->getType()->castAs<FunctionProtoType>();
1606  unsigned ParamsToSkip = 0;
1607 
1608  // The allocation size is the first argument.
1609  QualType sizeType = getContext().getSizeType();
1610  allocatorArgs.add(RValue::get(allocSize), sizeType);
1611  ++ParamsToSkip;
1612 
1613  if (allocSize != allocSizeWithoutCookie) {
1614  CharUnits cookieAlign = getSizeAlign(); // FIXME: Ask the ABI.
1615  allocAlign = std::max(allocAlign, cookieAlign);
1616  }
1617 
1618  // The allocation alignment may be passed as the second argument.
1619  if (E->passAlignment()) {
1620  QualType AlignValT = sizeType;
1621  if (allocatorType->getNumParams() > 1) {
1622  AlignValT = allocatorType->getParamType(1);
1623  assert(getContext().hasSameUnqualifiedType(
1624  AlignValT->castAs<EnumType>()->getDecl()->getIntegerType(),
1625  sizeType) &&
1626  "wrong type for alignment parameter");
1627  ++ParamsToSkip;
1628  } else {
1629  // Corner case, passing alignment to 'operator new(size_t, ...)'.
1630  assert(allocator->isVariadic() && "can't pass alignment to allocator");
1631  }
1632  allocatorArgs.add(
1633  RValue::get(llvm::ConstantInt::get(SizeTy, allocAlign.getQuantity())),
1634  AlignValT);
1635  }
1636 
1637  // FIXME: Why do we not pass a CalleeDecl here?
1638  EmitCallArgs(allocatorArgs, allocatorType, E->placement_arguments(),
1639  /*AC*/AbstractCallee(), /*ParamsToSkip*/ParamsToSkip);
1640 
1641  RValue RV =
1642  EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs);
1643 
1644  // Set !heapallocsite metadata on the call to operator new.
1645  if (getDebugInfo())
1646  if (auto *newCall = dyn_cast<llvm::CallBase>(RV.getScalarVal()))
1647  getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType,
1648  E->getExprLoc());
1649 
1650  // If this was a call to a global replaceable allocation function that does
1651  // not take an alignment argument, the allocator is known to produce
1652  // storage that's suitably aligned for any object that fits, up to a known
1653  // threshold. Otherwise assume it's suitably aligned for the allocated type.
1654  CharUnits allocationAlign = allocAlign;
1655  if (!E->passAlignment() &&
1657  unsigned AllocatorAlign = llvm::PowerOf2Floor(std::min<uint64_t>(
1658  Target.getNewAlign(), getContext().getTypeSize(allocType)));
1659  allocationAlign = std::max(
1660  allocationAlign, getContext().toCharUnitsFromBits(AllocatorAlign));
1661  }
1662 
1663  allocation = Address(RV.getScalarVal(), Int8Ty, allocationAlign);
1664  }
1665 
1666  // Emit a null check on the allocation result if the allocation
1667  // function is allowed to return null (because it has a non-throwing
1668  // exception spec or is the reserved placement new) and we have an
1669  // interesting initializer will be running sanitizers on the initialization.
1670  bool nullCheck = E->shouldNullCheckAllocation() &&
1671  (!allocType.isPODType(getContext()) || E->hasInitializer() ||
1673 
1674  llvm::BasicBlock *nullCheckBB = nullptr;
1675  llvm::BasicBlock *contBB = nullptr;
1676 
1677  // The null-check means that the initializer is conditionally
1678  // evaluated.
1679  ConditionalEvaluation conditional(*this);
1680 
1681  if (nullCheck) {
1682  conditional.begin(*this);
1683 
1684  nullCheckBB = Builder.GetInsertBlock();
1685  llvm::BasicBlock *notNullBB = createBasicBlock("new.notnull");
1686  contBB = createBasicBlock("new.cont");
1687 
1688  llvm::Value *isNull =
1689  Builder.CreateIsNull(allocation.getPointer(), "new.isnull");
1690  Builder.CreateCondBr(isNull, contBB, notNullBB);
1691  EmitBlock(notNullBB);
1692  }
1693 
1694  // If there's an operator delete, enter a cleanup to call it if an
1695  // exception is thrown.
1696  EHScopeStack::stable_iterator operatorDeleteCleanup;
1697  llvm::Instruction *cleanupDominator = nullptr;
1698  if (E->getOperatorDelete() &&
1700  EnterNewDeleteCleanup(*this, E, allocation, allocSize, allocAlign,
1701  allocatorArgs);
1702  operatorDeleteCleanup = EHStack.stable_begin();
1703  cleanupDominator = Builder.CreateUnreachable();
1704  }
1705 
1706  assert((allocSize == allocSizeWithoutCookie) ==
1707  CalculateCookiePadding(*this, E).isZero());
1708  if (allocSize != allocSizeWithoutCookie) {
1709  assert(E->isArray());
1710  allocation = CGM.getCXXABI().InitializeArrayCookie(*this, allocation,
1711  numElements,
1712  E, allocType);
1713  }
1714 
1715  llvm::Type *elementTy = ConvertTypeForMem(allocType);
1716  Address result = Builder.CreateElementBitCast(allocation, elementTy);
1717 
1718  // Passing pointer through launder.invariant.group to avoid propagation of
1719  // vptrs information which may be included in previous type.
1720  // To not break LTO with different optimizations levels, we do it regardless
1721  // of optimization level.
1722  if (CGM.getCodeGenOpts().StrictVTablePointers &&
1723  allocator->isReservedGlobalPlacementOperator())
1724  result = Builder.CreateLaunderInvariantGroup(result);
1725 
1726  // Emit sanitizer checks for pointer value now, so that in the case of an
1727  // array it was checked only once and not at each constructor call. We may
1728  // have already checked that the pointer is non-null.
1729  // FIXME: If we have an array cookie and a potentially-throwing allocator,
1730  // we'll null check the wrong pointer here.
1731  SanitizerSet SkippedChecks;
1732  SkippedChecks.set(SanitizerKind::Null, nullCheck);
1735  result.getPointer(), allocType, result.getAlignment(),
1736  SkippedChecks, numElements);
1737 
1738  EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
1739  allocSizeWithoutCookie);
1740  llvm::Value *resultPtr = result.getPointer();
1741  if (E->isArray()) {
1742  // NewPtr is a pointer to the base element type. If we're
1743  // allocating an array of arrays, we'll need to cast back to the
1744  // array pointer type.
1745  llvm::Type *resultType = ConvertTypeForMem(E->getType());
1746  if (resultPtr->getType() != resultType)
1747  resultPtr = Builder.CreateBitCast(resultPtr, resultType);
1748  }
1749 
1750  // Deactivate the 'operator delete' cleanup if we finished
1751  // initialization.
1752  if (operatorDeleteCleanup.isValid()) {
1753  DeactivateCleanupBlock(operatorDeleteCleanup, cleanupDominator);
1754  cleanupDominator->eraseFromParent();
1755  }
1756 
1757  if (nullCheck) {
1758  conditional.end(*this);
1759 
1760  llvm::BasicBlock *notNullBB = Builder.GetInsertBlock();
1761  EmitBlock(contBB);
1762 
1763  llvm::PHINode *PHI = Builder.CreatePHI(resultPtr->getType(), 2);
1764  PHI->addIncoming(resultPtr, notNullBB);
1765  PHI->addIncoming(llvm::Constant::getNullValue(resultPtr->getType()),
1766  nullCheckBB);
1767 
1768  resultPtr = PHI;
1769  }
1770 
1771  return resultPtr;
1772 }
1773 
1775  llvm::Value *Ptr, QualType DeleteTy,
1776  llvm::Value *NumElements,
1777  CharUnits CookieSize) {
1778  assert((!NumElements && CookieSize.isZero()) ||
1779  DeleteFD->getOverloadedOperator() == OO_Array_Delete);
1780 
1781  const auto *DeleteFTy = DeleteFD->getType()->castAs<FunctionProtoType>();
1782  CallArgList DeleteArgs;
1783 
1784  auto Params = getUsualDeleteParams(DeleteFD);
1785  auto ParamTypeIt = DeleteFTy->param_type_begin();
1786 
1787  // Pass the pointer itself.
1788  QualType ArgTy = *ParamTypeIt++;
1789  llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy));
1790  DeleteArgs.add(RValue::get(DeletePtr), ArgTy);
1791 
1792  // Pass the std::destroying_delete tag if present.
1793  llvm::AllocaInst *DestroyingDeleteTag = nullptr;
1794  if (Params.DestroyingDelete) {
1795  QualType DDTag = *ParamTypeIt++;
1796  llvm::Type *Ty = getTypes().ConvertType(DDTag);
1797  CharUnits Align = CGM.getNaturalTypeAlignment(DDTag);
1798  DestroyingDeleteTag = CreateTempAlloca(Ty, "destroying.delete.tag");
1799  DestroyingDeleteTag->setAlignment(Align.getAsAlign());
1800  DeleteArgs.add(
1801  RValue::getAggregate(Address(DestroyingDeleteTag, Ty, Align)), DDTag);
1802  }
1803 
1804  // Pass the size if the delete function has a size_t parameter.
1805  if (Params.Size) {
1806  QualType SizeType = *ParamTypeIt++;
1807  CharUnits DeleteTypeSize = getContext().getTypeSizeInChars(DeleteTy);
1808  llvm::Value *Size = llvm::ConstantInt::get(ConvertType(SizeType),
1809  DeleteTypeSize.getQuantity());
1810 
1811  // For array new, multiply by the number of elements.
1812  if (NumElements)
1813  Size = Builder.CreateMul(Size, NumElements);
1814 
1815  // If there is a cookie, add the cookie size.
1816  if (!CookieSize.isZero())
1817  Size = Builder.CreateAdd(
1818  Size, llvm::ConstantInt::get(SizeTy, CookieSize.getQuantity()));
1819 
1820  DeleteArgs.add(RValue::get(Size), SizeType);
1821  }
1822 
1823  // Pass the alignment if the delete function has an align_val_t parameter.
1824  if (Params.Alignment) {
1825  QualType AlignValType = *ParamTypeIt++;
1826  CharUnits DeleteTypeAlign =
1827  getContext().toCharUnitsFromBits(getContext().getTypeAlignIfKnown(
1828  DeleteTy, true /* NeedsPreferredAlignment */));
1829  llvm::Value *Align = llvm::ConstantInt::get(ConvertType(AlignValType),
1830  DeleteTypeAlign.getQuantity());
1831  DeleteArgs.add(RValue::get(Align), AlignValType);
1832  }
1833 
1834  assert(ParamTypeIt == DeleteFTy->param_type_end() &&
1835  "unknown parameter to usual delete function");
1836 
1837  // Emit the call to delete.
1838  EmitNewDeleteCall(*this, DeleteFD, DeleteFTy, DeleteArgs);
1839 
1840  // If call argument lowering didn't use the destroying_delete_t alloca,
1841  // remove it again.
1842  if (DestroyingDeleteTag && DestroyingDeleteTag->use_empty())
1843  DestroyingDeleteTag->eraseFromParent();
1844 }
1845 
1846 namespace {
1847  /// Calls the given 'operator delete' on a single object.
1848  struct CallObjectDelete final : EHScopeStack::Cleanup {
1849  llvm::Value *Ptr;
1850  const FunctionDecl *OperatorDelete;
1851  QualType ElementType;
1852 
1853  CallObjectDelete(llvm::Value *Ptr,
1854  const FunctionDecl *OperatorDelete,
1855  QualType ElementType)
1856  : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {}
1857 
1858  void Emit(CodeGenFunction &CGF, Flags flags) override {
1859  CGF.EmitDeleteCall(OperatorDelete, Ptr, ElementType);
1860  }
1861  };
1862 }
1863 
1864 void
1866  llvm::Value *CompletePtr,
1867  QualType ElementType) {
1868  EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup, CompletePtr,
1869  OperatorDelete, ElementType);
1870 }
1871 
1872 /// Emit the code for deleting a single object with a destroying operator
1873 /// delete. If the element type has a non-virtual destructor, Ptr has already
1874 /// been converted to the type of the parameter of 'operator delete'. Otherwise
1875 /// Ptr points to an object of the static type.
1877  const CXXDeleteExpr *DE, Address Ptr,
1878  QualType ElementType) {
1879  auto *Dtor = ElementType->getAsCXXRecordDecl()->getDestructor();
1880  if (Dtor && Dtor->isVirtual())
1881  CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
1882  Dtor);
1883  else
1884  CGF.EmitDeleteCall(DE->getOperatorDelete(), Ptr.getPointer(), ElementType);
1885 }
1886 
1887 /// Emit the code for deleting a single object.
1888 /// \return \c true if we started emitting UnconditionalDeleteBlock, \c false
1889 /// if not.
1891  const CXXDeleteExpr *DE,
1892  Address Ptr,
1893  QualType ElementType,
1894  llvm::BasicBlock *UnconditionalDeleteBlock) {
1895  // C++11 [expr.delete]p3:
1896  // If the static type of the object to be deleted is different from its
1897  // dynamic type, the static type shall be a base class of the dynamic type
1898  // of the object to be deleted and the static type shall have a virtual
1899  // destructor or the behavior is undefined.
1901  DE->getExprLoc(), Ptr.getPointer(),
1902  ElementType);
1903 
1904  const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
1905  assert(!OperatorDelete->isDestroyingOperatorDelete());
1906 
1907  // Find the destructor for the type, if applicable. If the
1908  // destructor is virtual, we'll just emit the vcall and return.
1909  const CXXDestructorDecl *Dtor = nullptr;
1910  if (const RecordType *RT = ElementType->getAs<RecordType>()) {
1911  CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
1912  if (RD->hasDefinition() && !RD->hasTrivialDestructor()) {
1913  Dtor = RD->getDestructor();
1914 
1915  if (Dtor->isVirtual()) {
1916  bool UseVirtualCall = true;
1917  const Expr *Base = DE->getArgument();
1918  if (auto *DevirtualizedDtor =
1919  dyn_cast_or_null<const CXXDestructorDecl>(
1920  Dtor->getDevirtualizedMethod(
1921  Base, CGF.CGM.getLangOpts().AppleKext))) {
1922  UseVirtualCall = false;
1923  const CXXRecordDecl *DevirtualizedClass =
1924  DevirtualizedDtor->getParent();
1925  if (declaresSameEntity(getCXXRecord(Base), DevirtualizedClass)) {
1926  // Devirtualized to the class of the base type (the type of the
1927  // whole expression).
1928  Dtor = DevirtualizedDtor;
1929  } else {
1930  // Devirtualized to some other type. Would need to cast the this
1931  // pointer to that type but we don't have support for that yet, so
1932  // do a virtual call. FIXME: handle the case where it is
1933  // devirtualized to the derived type (the type of the inner
1934  // expression) as in EmitCXXMemberOrOperatorMemberCallExpr.
1935  UseVirtualCall = true;
1936  }
1937  }
1938  if (UseVirtualCall) {
1939  CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
1940  Dtor);
1941  return false;
1942  }
1943  }
1944  }
1945  }
1946 
1947  // Make sure that we call delete even if the dtor throws.
1948  // This doesn't have to a conditional cleanup because we're going
1949  // to pop it off in a second.
1950  CGF.EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup,
1951  Ptr.getPointer(),
1952  OperatorDelete, ElementType);
1953 
1954  if (Dtor)
1956  /*ForVirtualBase=*/false,
1957  /*Delegating=*/false,
1958  Ptr, ElementType);
1959  else if (auto Lifetime = ElementType.getObjCLifetime()) {
1960  switch (Lifetime) {
1961  case Qualifiers::OCL_None:
1964  break;
1965 
1968  break;
1969 
1970  case Qualifiers::OCL_Weak:
1971  CGF.EmitARCDestroyWeak(Ptr);
1972  break;
1973  }
1974  }
1975 
1976  // When optimizing for size, call 'operator delete' unconditionally.
1977  if (CGF.CGM.getCodeGenOpts().OptimizeSize > 1) {
1978  CGF.EmitBlock(UnconditionalDeleteBlock);
1979  CGF.PopCleanupBlock();
1980  return true;
1981  }
1982 
1983  CGF.PopCleanupBlock();
1984  return false;
1985 }
1986 
1987 namespace {
1988  /// Calls the given 'operator delete' on an array of objects.
1989  struct CallArrayDelete final : EHScopeStack::Cleanup {
1990  llvm::Value *Ptr;
1991  const FunctionDecl *OperatorDelete;
1992  llvm::Value *NumElements;
1993  QualType ElementType;
1994  CharUnits CookieSize;
1995 
1996  CallArrayDelete(llvm::Value *Ptr,
1997  const FunctionDecl *OperatorDelete,
1998  llvm::Value *NumElements,
1999  QualType ElementType,
2000  CharUnits CookieSize)
2001  : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements),
2002  ElementType(ElementType), CookieSize(CookieSize) {}
2003 
2004  void Emit(CodeGenFunction &CGF, Flags flags) override {
2005  CGF.EmitDeleteCall(OperatorDelete, Ptr, ElementType, NumElements,
2006  CookieSize);
2007  }
2008  };
2009 }
2010 
2011 /// Emit the code for deleting an array of objects.
2013  const CXXDeleteExpr *E,
2014  Address deletedPtr,
2015  QualType elementType) {
2016  llvm::Value *numElements = nullptr;
2017  llvm::Value *allocatedPtr = nullptr;
2018  CharUnits cookieSize;
2019  CGF.CGM.getCXXABI().ReadArrayCookie(CGF, deletedPtr, E, elementType,
2020  numElements, allocatedPtr, cookieSize);
2021 
2022  assert(allocatedPtr && "ReadArrayCookie didn't set allocated pointer");
2023 
2024  // Make sure that we call delete even if one of the dtors throws.
2025  const FunctionDecl *operatorDelete = E->getOperatorDelete();
2026  CGF.EHStack.pushCleanup<CallArrayDelete>(NormalAndEHCleanup,
2027  allocatedPtr, operatorDelete,
2028  numElements, elementType,
2029  cookieSize);
2030 
2031  // Destroy the elements.
2032  if (QualType::DestructionKind dtorKind = elementType.isDestructedType()) {
2033  assert(numElements && "no element count for a type with a destructor!");
2034 
2035  CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
2036  CharUnits elementAlign =
2037  deletedPtr.getAlignment().alignmentOfArrayElement(elementSize);
2038 
2039  llvm::Value *arrayBegin = deletedPtr.getPointer();
2040  llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP(
2041  deletedPtr.getElementType(), arrayBegin, numElements, "delete.end");
2042 
2043  // Note that it is legal to allocate a zero-length array, and we
2044  // can never fold the check away because the length should always
2045  // come from a cookie.
2046  CGF.emitArrayDestroy(arrayBegin, arrayEnd, elementType, elementAlign,
2047  CGF.getDestroyer(dtorKind),
2048  /*checkZeroLength*/ true,
2049  CGF.needsEHCleanup(dtorKind));
2050  }
2051 
2052  // Pop the cleanup block.
2053  CGF.PopCleanupBlock();
2054 }
2055 
2057  const Expr *Arg = E->getArgument();
2058  Address Ptr = EmitPointerWithAlignment(Arg);
2059 
2060  // Null check the pointer.
2061  //
2062  // We could avoid this null check if we can determine that the object
2063  // destruction is trivial and doesn't require an array cookie; we can
2064  // unconditionally perform the operator delete call in that case. For now, we
2065  // assume that deleted pointers are null rarely enough that it's better to
2066  // keep the branch. This might be worth revisiting for a -O0 code size win.
2067  llvm::BasicBlock *DeleteNotNull = createBasicBlock("delete.notnull");
2068  llvm::BasicBlock *DeleteEnd = createBasicBlock("delete.end");
2069 
2070  llvm::Value *IsNull = Builder.CreateIsNull(Ptr.getPointer(), "isnull");
2071 
2072  Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
2073  EmitBlock(DeleteNotNull);
2074 
2075  QualType DeleteTy = E->getDestroyedType();
2076 
2077  // A destroying operator delete overrides the entire operation of the
2078  // delete expression.
2080  EmitDestroyingObjectDelete(*this, E, Ptr, DeleteTy);
2081  EmitBlock(DeleteEnd);
2082  return;
2083  }
2084 
2085  // We might be deleting a pointer to array. If so, GEP down to the
2086  // first non-array element.
2087  // (this assumes that A(*)[3][7] is converted to [3 x [7 x %A]]*)
2088  if (DeleteTy->isConstantArrayType()) {
2089  llvm::Value *Zero = Builder.getInt32(0);
2091 
2092  GEP.push_back(Zero); // point at the outermost array
2093 
2094  // For each layer of array type we're pointing at:
2095  while (const ConstantArrayType *Arr
2096  = getContext().getAsConstantArrayType(DeleteTy)) {
2097  // 1. Unpeel the array type.
2098  DeleteTy = Arr->getElementType();
2099 
2100  // 2. GEP to the first element of the array.
2101  GEP.push_back(Zero);
2102  }
2103 
2104  Ptr = Address(Builder.CreateInBoundsGEP(Ptr.getElementType(),
2105  Ptr.getPointer(), GEP, "del.first"),
2106  ConvertTypeForMem(DeleteTy), Ptr.getAlignment());
2107  }
2108 
2109  assert(ConvertTypeForMem(DeleteTy) == Ptr.getElementType());
2110 
2111  if (E->isArrayForm()) {
2112  EmitArrayDelete(*this, E, Ptr, DeleteTy);
2113  EmitBlock(DeleteEnd);
2114  } else {
2115  if (!EmitObjectDelete(*this, E, Ptr, DeleteTy, DeleteEnd))
2116  EmitBlock(DeleteEnd);
2117  }
2118 }
2119 
2120 static bool isGLValueFromPointerDeref(const Expr *E) {
2121  E = E->IgnoreParens();
2122 
2123  if (const auto *CE = dyn_cast<CastExpr>(E)) {
2124  if (!CE->getSubExpr()->isGLValue())
2125  return false;
2126  return isGLValueFromPointerDeref(CE->getSubExpr());
2127  }
2128 
2129  if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
2130  return isGLValueFromPointerDeref(OVE->getSourceExpr());
2131 
2132  if (const auto *BO = dyn_cast<BinaryOperator>(E))
2133  if (BO->getOpcode() == BO_Comma)
2134  return isGLValueFromPointerDeref(BO->getRHS());
2135 
2136  if (const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
2137  return isGLValueFromPointerDeref(ACO->getTrueExpr()) ||
2138  isGLValueFromPointerDeref(ACO->getFalseExpr());
2139 
2140  // C++11 [expr.sub]p1:
2141  // The expression E1[E2] is identical (by definition) to *((E1)+(E2))
2142  if (isa<ArraySubscriptExpr>(E))
2143  return true;
2144 
2145  if (const auto *UO = dyn_cast<UnaryOperator>(E))
2146  if (UO->getOpcode() == UO_Deref)
2147  return true;
2148 
2149  return false;
2150 }
2151 
2152 static llvm::Value *EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E,
2153  llvm::Type *StdTypeInfoPtrTy) {
2154  // Get the vtable pointer.
2155  Address ThisPtr = CGF.EmitLValue(E).getAddress(CGF);
2156 
2157  QualType SrcRecordTy = E->getType();
2158 
2159  // C++ [class.cdtor]p4:
2160  // If the operand of typeid refers to the object under construction or
2161  // destruction and the static type of the operand is neither the constructor
2162  // or destructor’s class nor one of its bases, the behavior is undefined.
2164  ThisPtr.getPointer(), SrcRecordTy);
2165 
2166  // C++ [expr.typeid]p2:
2167  // If the glvalue expression is obtained by applying the unary * operator to
2168  // a pointer and the pointer is a null pointer value, the typeid expression
2169  // throws the std::bad_typeid exception.
2170  //
2171  // However, this paragraph's intent is not clear. We choose a very generous
2172  // interpretation which implores us to consider comma operators, conditional
2173  // operators, parentheses and other such constructs.
2175  isGLValueFromPointerDeref(E), SrcRecordTy)) {
2176  llvm::BasicBlock *BadTypeidBlock =
2177  CGF.createBasicBlock("typeid.bad_typeid");
2178  llvm::BasicBlock *EndBlock = CGF.createBasicBlock("typeid.end");
2179 
2180  llvm::Value *IsNull = CGF.Builder.CreateIsNull(ThisPtr.getPointer());
2181  CGF.Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);
2182 
2183  CGF.EmitBlock(BadTypeidBlock);
2184  CGF.CGM.getCXXABI().EmitBadTypeidCall(CGF);
2185  CGF.EmitBlock(EndBlock);
2186  }
2187 
2188  return CGF.CGM.getCXXABI().EmitTypeid(CGF, SrcRecordTy, ThisPtr,
2189  StdTypeInfoPtrTy);
2190 }
2191 
2193  llvm::Type *StdTypeInfoPtrTy =
2194  ConvertType(E->getType())->getPointerTo();
2195 
2196  if (E->isTypeOperand()) {
2197  llvm::Constant *TypeInfo =
2199  return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy);
2200  }
2201 
2202  // C++ [expr.typeid]p2:
2203  // When typeid is applied to a glvalue expression whose type is a
2204  // polymorphic class type, the result refers to a std::type_info object
2205  // representing the type of the most derived object (that is, the dynamic
2206  // type) to which the glvalue refers.
2207  // If the operand is already most derived object, no need to look up vtable.
2208  if (E->isPotentiallyEvaluated() && !E->isMostDerived(getContext()))
2209  return EmitTypeidFromVTable(*this, E->getExprOperand(),
2210  StdTypeInfoPtrTy);
2211 
2212  QualType OperandTy = E->getExprOperand()->getType();
2213  return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(OperandTy),
2214  StdTypeInfoPtrTy);
2215 }
2216 
2217 static llvm::Value *EmitDynamicCastToNull(CodeGenFunction &CGF,
2218  QualType DestTy) {
2219  llvm::Type *DestLTy = CGF.ConvertType(DestTy);
2220  if (DestTy->isPointerType())
2221  return llvm::Constant::getNullValue(DestLTy);
2222 
2223  /// C++ [expr.dynamic.cast]p9:
2224  /// A failed cast to reference type throws std::bad_cast
2225  if (!CGF.CGM.getCXXABI().EmitBadCastCall(CGF))
2226  return nullptr;
2227 
2228  CGF.EmitBlock(CGF.createBasicBlock("dynamic_cast.end"));
2229  return llvm::UndefValue::get(DestLTy);
2230 }
2231 
2233  const CXXDynamicCastExpr *DCE) {
2234  CGM.EmitExplicitCastExprType(DCE, this);
2235  QualType DestTy = DCE->getTypeAsWritten();
2236 
2237  QualType SrcTy = DCE->getSubExpr()->getType();
2238 
2239  // C++ [expr.dynamic.cast]p7:
2240  // If T is "pointer to cv void," then the result is a pointer to the most
2241  // derived object pointed to by v.
2242  const PointerType *DestPTy = DestTy->getAs<PointerType>();
2243 
2244  bool isDynamicCastToVoid;
2245  QualType SrcRecordTy;
2246  QualType DestRecordTy;
2247  if (DestPTy) {
2248  isDynamicCastToVoid = DestPTy->getPointeeType()->isVoidType();
2249  SrcRecordTy = SrcTy->castAs<PointerType>()->getPointeeType();
2250  DestRecordTy = DestPTy->getPointeeType();
2251  } else {
2252  isDynamicCastToVoid = false;
2253  SrcRecordTy = SrcTy;
2254  DestRecordTy = DestTy->castAs<ReferenceType>()->getPointeeType();
2255  }
2256 
2257  // C++ [class.cdtor]p5:
2258  // If the operand of the dynamic_cast refers to the object under
2259  // construction or destruction and the static type of the operand is not a
2260  // pointer to or object of the constructor or destructor’s own class or one
2261  // of its bases, the dynamic_cast results in undefined behavior.
2263  SrcRecordTy);
2264 
2265  if (DCE->isAlwaysNull())
2266  if (llvm::Value *T = EmitDynamicCastToNull(*this, DestTy))
2267  return T;
2268 
2269  assert(SrcRecordTy->isRecordType() && "source type must be a record type!");
2270 
2271  // C++ [expr.dynamic.cast]p4:
2272  // If the value of v is a null pointer value in the pointer case, the result
2273  // is the null pointer value of type T.
2274  bool ShouldNullCheckSrcValue =
2276  SrcRecordTy);
2277 
2278  llvm::BasicBlock *CastNull = nullptr;
2279  llvm::BasicBlock *CastNotNull = nullptr;
2280  llvm::BasicBlock *CastEnd = createBasicBlock("dynamic_cast.end");
2281 
2282  if (ShouldNullCheckSrcValue) {
2283  CastNull = createBasicBlock("dynamic_cast.null");
2284  CastNotNull = createBasicBlock("dynamic_cast.notnull");
2285 
2286  llvm::Value *IsNull = Builder.CreateIsNull(ThisAddr.getPointer());
2287  Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
2288  EmitBlock(CastNotNull);
2289  }
2290 
2291  llvm::Value *Value;
2292  if (isDynamicCastToVoid) {
2293  Value = CGM.getCXXABI().EmitDynamicCastToVoid(*this, ThisAddr, SrcRecordTy,
2294  DestTy);
2295  } else {
2296  assert(DestRecordTy->isRecordType() &&
2297  "destination type must be a record type!");
2298  Value = CGM.getCXXABI().EmitDynamicCastCall(*this, ThisAddr, SrcRecordTy,
2299  DestTy, DestRecordTy, CastEnd);
2300  CastNotNull = Builder.GetInsertBlock();
2301  }
2302 
2303  if (ShouldNullCheckSrcValue) {
2304  EmitBranch(CastEnd);
2305 
2306  EmitBlock(CastNull);
2307  EmitBranch(CastEnd);
2308  }
2309 
2310  EmitBlock(CastEnd);
2311 
2312  if (ShouldNullCheckSrcValue) {
2313  llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2);
2314  PHI->addIncoming(Value, CastNotNull);
2315  PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
2316 
2317  Value = PHI;
2318  }
2319 
2320  return Value;
2321 }
clang::CodeGen::CGCXXABI::ReadArrayCookie
virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)
Reads the array cookie associated with the given pointer, if it has one.
Definition: CGCXXABI.cpp:248
clang::CXXPseudoDestructorExpr::getDestroyedType
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:334
clang::CXXMethodDecl::getThisType
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2452
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:208
clang::CXXNewExpr::passAlignment
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
Definition: ExprCXX.h:2349
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:2714
clang::ASTContext::getTypeSizeInChars
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Definition: ASTContext.cpp:2462
clang::FunctionProtoType::param_type_begin
param_type_iterator param_type_begin() const
Definition: Type.h:4267
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:1129
clang::CharUnits::isOne
bool isOne() const
isOne - Test whether the quantity equals one.
Definition: CharUnits.h:119
clang::CXXConstructExpr::CK_Complete
@ CK_Complete
Definition: ExprCXX.h:1465
clang::CodeGen::CGBuilderTy::CreateMemCpy
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:309
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6838
clang::CXXMemberCallExpr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
Definition: ExprCXX.h:218
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::CodeGen::CodeGenFunction::getTypeSize
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
Definition: CGStmtOpenMP.cpp:305
clang::CodeGen::CGDebugInfo::addHeapAllocSiteMetadata
void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy, SourceLocation Loc)
Add heapallocsite metadata for MSAllocator calls.
Definition: CGDebugInfo.cpp:2348
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2231
clang::Type::getAsArrayTypeUnsafe
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:7296
clang::CodeGen::LValueBaseInfo
Definition: CGValue.h:154
clang::QualType::getObjCLifetime
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1128
clang::FunctionProtoType::param_type_end
param_type_iterator param_type_end() const
Definition: Type.h:4271
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2421
clang::CXXMethodDecl::isCopyAssignmentOperator
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Definition: DeclCXX.cpp:2360
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:1956
clang::CodeGen::CGCXXABI::EmitBadCastCall
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
EmitArrayDelete
static void EmitArrayDelete(CodeGenFunction &CGF, const CXXDeleteExpr *E, Address deletedPtr, QualType elementType)
Emit the code for deleting an array of objects.
Definition: CGExprCXX.cpp:2012
clang::CallExpr::arg_end
arg_iterator arg_end()
Definition: Expr.h:3048
clang::CallExpr::arg_begin
arg_iterator arg_begin()
Definition: Expr.h:3045
clang::CharUnits::getAsAlign
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
Definition: CharUnits.h:183
StoreAnyExprIntoOneUnit
static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init, QualType AllocType, Address NewPtr, AggValueSlot::Overlap_t MayOverlap)
Definition: CGExprCXX.cpp:957
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::CXXPseudoDestructorExpr
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2534
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:201
clang::QualType::hasStrongOrWeakObjCLifetime
bool hasStrongOrWeakObjCLifetime() const
Definition: Type.h:1136
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
type
clang::CodeGen::RValue::getAggregate
static RValue getAggregate(Address addr, bool isVolatile=false)
Definition: CGValue.h:110
clang::CodeGen::CodeGenFunction::sanitizePerformTypeCheck
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
Definition: CGExpr.cpp:668
clang::CXXMethodDecl::isStatic
bool isStatic() const
Definition: DeclCXX.cpp:2092
clang::CodeGen::CodeGenFunction::EmitARCDestroyWeak
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
Definition: CGObjC.cpp:2606
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2557
clang::CallExpr::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1531
clang::RecordDecl::mayInsertExtraPadding
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:4740
CodeGenFunction.h
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:4683
clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorCall
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, const CGCallee &Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, CallArgList *RtlArgs)
Definition: CGExprCXX.cpp:78
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::CodeGen::EHScopeStack::stable_iterator::isValid
bool isValid() const
Definition: EHScopeStack.h:113
clang::CodeGen::CodeGenFunction::TCK_DynamicOperation
@ TCK_DynamicOperation
Checking the operand of a dynamic_cast or a typeid expression.
Definition: CodeGenFunction.h:2986
clang::ConstantArrayType
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2942
clang::CodeGen::AggValueSlot::DoesNotNeedGCBarriers
@ DoesNotNeedGCBarriers
Definition: CGValue.h:554
clang::CodeGen::Address::getAlignment
CharUnits getAlignment() const
Return the alignment of this pointer.
Definition: Address.h:120
clang::CodeGen::CodeGenTypeCache::getSizeAlign
CharUnits getSizeAlign() const
Definition: CodeGenTypeCache.h:111
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:3937
clang::Qualifiers::OCL_Weak
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:178
clang::CodeGen::CGCXXABI::emitVirtualObjectDelete
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
clang::CodeGen::CodeGenFunction::EmitSynthesizedCXXCopyCtorCall
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E)
Definition: CGClass.cpp:2352
clang::TargetInfo::getNewAlign
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
Definition: TargetInfo.h:651
llvm::SmallVector
Definition: LLVM.h:38
clang::CXXTypeidExpr::isPotentiallyEvaluated
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
Definition: ExprCXX.cpp:134
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:6527
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:341
clang::CXXNewExpr::getNumPlacementArgs
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2292
clang::CodeGen::CodeGenFunction::PopCleanupBlock
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
Definition: CGCleanup.cpp:659
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3525
clang::CodeGen::CodeGenModule::getSize
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
Definition: CodeGenModule.cpp:1076
clang::CXXNewExpr::getOperatorNew
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2257
clang::CXXDeleteExpr::isArrayForm
bool isArrayForm() const
Definition: ExprCXX.h:2441
clang::ASTContext::DeclarationNames
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:659
clang::CXXConstructExpr::requiresZeroInitialization
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition: ExprCXX.h:1571
clang::CodeGen::CGCXXABI::InitializeArrayCookie
virtual Address InitializeArrayCookie(CodeGenFunction &CGF, Address NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
Initialize the array cookie for the given allocation.
Definition: CGCXXABI.cpp:219
clang::CodeGen::CodeGenTypeCache::getPointerAlign
CharUnits getPointerAlign() const
Definition: CodeGenTypeCache.h:117
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:675
clang::NestedNameSpecifier
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Definition: NestedNameSpecifier.h:50
clang::CXXNewExpr::isArray
bool isArray() const
Definition: ExprCXX.h:2262
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:155
clang::CXXTypeidExpr
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:839
clang::QualType::getCanonicalType
QualType getCanonicalType() const
Definition: Type.h:6539
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:91
clang::CodeGen::CodeGenFunction::EmitARCDestroyStrong
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
Definition: CGObjC.cpp:2434
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6789
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::CodeGen::CodeGenFunction::EmitNewArrayInitializer
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
Definition: CGExprCXX.cpp:985
clang::ASTRecordLayout::getNonVirtualAlignment
CharUnits getNonVirtualAlignment() const
getNonVirtualAlignment - Get the non-virtual alignment (in chars) of an object, which is the alignmen...
Definition: RecordLayout.h:218
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:2430
clang::CXXNewExpr
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2139
clang::CodeGen::CodeGenFunction::pushIrregularPartialArrayCleanup
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the ...
Definition: CGDecl.cpp:2376
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:97
EmitNewInitializer
static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
Definition: CGExprCXX.cpp:1290
CGObjCRuntime.h
clang::InitListExpr
Describes an C or C++ initializer list.
Definition: Expr.h:4791
TargetInfo.h
clang::Qualifiers::OCL_ExplicitNone
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:168
clang::Ctor_Base
@ Ctor_Base
Base object ctor.
Definition: ABI.h:26
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:698
clang::Ctor_Complete
@ Ctor_Complete
Complete object ctor.
Definition: ABI.h:25
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7037
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6570
clang::MemberExpr::getQualifier
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
Definition: Expr.h:3275
clang::CodeGen::CodeGenFunction::getDestroyer
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:2091
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::CodeGen::CodeGenFunction::EmitDynamicCast
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
Definition: CGExprCXX.cpp:2232
clang::CodeGen::CodeGenFunction::CreateTempAlloca
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
Definition: CGExpr.cpp:110
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3851
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:194
clang::CodeGen::CodeGenFunction::MustTailCall
const CallExpr * MustTailCall
Definition: CodeGenFunction.h:563
clang::CodeGen::CodeGenFunction::EmitCXXMemberCallExpr
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGExprCXX.cpp:181
clang::CXXNewExpr::getAllocatedType
QualType getAllocatedType() const
Definition: ExprCXX.h:2232
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::EmitCUDAKernelCallExpr
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGExprCXX.cpp:491
clang::CodeGen::CGCXXABI::EmitTypeid
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, Address ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
clang::CXXTypeidExpr::isMostDerived
bool isMostDerived(ASTContext &Context) const
Best-effort check if the expression operand refers to a most derived object.
Definition: ExprCXX.cpp:149
ConstantEmitter.h
clang::CXXTypeidExpr::getExprOperand
Expr * getExprOperand() const
Definition: ExprCXX.h:886
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:144
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1078
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:286
isGLValueFromPointerDeref
static bool isGLValueFromPointerDeref(const Expr *E)
Definition: CGExprCXX.cpp:2120
clang::MemberExpr::hasQualifier
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
Definition: Expr.h:3261
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:269
CGDebugInfo.h
clang::CXXMethodDecl::getCorrespondingMethodInClass
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
Definition: DeclCXX.cpp:2145
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::CXXMethodDecl::isMoveAssignmentOperator
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Definition: DeclCXX.cpp:2381
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1500
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:1942
clang::CodeGen::CodeGenFunction::EmitCXXDestructorCall
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
Definition: CGClass.cpp:2465
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
clang::TypeLoc::getBeginLoc
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:191
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CodeGenOptions.h
clang::Qualifiers::getAddressSpace
LangAS getAddressSpace() const
Definition: Type.h:363
clang::ASTContext::getTypeAlignInChars
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
Definition: ASTContext.cpp:2471
clang::CodeGen::InvariantValue::save
static saved_type save(CodeGenFunction &CGF, type value)
Definition: EHScopeStack.h:59
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:360
clang::TypeInfo
Definition: ASTContext.h:178
clang::CallExpr::getCallee
Expr * getCallee()
Definition: Expr.h:2951
V
#define V(N, I)
Definition: ASTContext.h:3176
clang::CodeGen::CodeGenFunction::EmitCXXConstructExpr
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
Definition: CGExprCXX.cpp:585
CalculateCookiePadding
static CharUnits CalculateCookiePadding(CodeGenFunction &CGF, const CXXNewExpr *E)
Definition: CGExprCXX.cpp:682
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
clang::CodeGen::CGBuilderTy::CreateConstInBoundsGEP
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ...
Definition: CGBuilder.h:229
clang::CodeGen::TBAAAccessInfo
Definition: CodeGenTBAA.h:41
clang::CallExpr::getDirectCallee
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition: Expr.h:2971
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4647
clang::CXXCtorType
CXXCtorType
C++ constructor types.
Definition: ABI.h:24
clang::SanitizerSet
Definition: Sanitizers.h:153
clang::CodeGen::AggValueSlot::IsSanitizerChecked
@ IsSanitizerChecked
Definition: CGValue.h:555
clang::CodeGen::EHScopeStack::Cleanup
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
clang::CXXMethodDecl::isInstance
bool isInstance() const
Definition: DeclCXX.h:1995
clang::ASTContext::getAsConstantArrayType
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2690
clang::CodeGen::ARCPreciseLifetime
@ ARCPreciseLifetime
Definition: CGValue.h:125
clang::FunctionDecl::isTrivial
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2223
clang::QualType::getAddressSpace
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6621
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3807
EmitTypeidFromVTable
static llvm::Value * EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, llvm::Type *StdTypeInfoPtrTy)
Definition: CGExprCXX.cpp:2152
clang::CXXNewExpr::getInitializer
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2331
clang::Qualifiers::OCL_Strong
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:175
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::MemberExpr::isArrow
bool isArrow() const
Definition: Expr.h:3348
clang::CodeGen::CodeGenFunction::EmitCXXNewExpr
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
Definition: CGExprCXX.cpp:1552
clang::CodeGen::CodeGenFunction::EmitCastToVoidPtr
llvm::Value * EmitCastToVoidPtr(llvm::Value *value)
Emit a cast to void* in the appropriate address space.
Definition: CGExpr.cpp:54
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:703
clang::CodeGen::Address::getType
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:99
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
clang::ASTContext::getSizeType
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Definition: ASTContext.cpp:5823
CGFunctionInfo.h
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2896
clang::DeclarationNameTable::getCXXOperatorName
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
Definition: DeclarationName.h:648
clang::MemberPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2860
clang::CodeGen::TEK_Complex
@ TEK_Complex
Definition: CodeGenFunction.h:108
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::ASTContext::getConstantArrayElementCount
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
Definition: ASTContext.cpp:6809
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7243
clang::CodeGen::CodeGenFunction::getDebugInfo
CGDebugInfo * getDebugInfo()
Definition: CodeGenFunction.h:1983
EmitObjectDelete
static bool EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, llvm::BasicBlock *UnconditionalDeleteBlock)
Emit the code for deleting a single object.
Definition: CGExprCXX.cpp:1890
clang::CallExpr::getArg
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2992
clang::CodeGen::CGCXXABI::getThisArgumentTypeForMethod
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
Definition: CGCXXABI.h:371
clang::CodeGen::CodeGenFunction::EmitCXXPseudoDestructorExpr
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
Definition: CGExprCXX.cpp:120
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:2393
clang::FunctionProtoType::getParamType
QualType getParamType(unsigned i) const
Definition: Type.h:4110
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::CodeGen::CGCXXABI::adjustThisArgumentForVirtualFunctionCall
virtual Address adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, Address This, bool VirtualCall)
Perform ABI-specific "this" argument adjustment required prior to a call of a virtual function.
Definition: CGCXXABI.h:379
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:704
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2688
clang::CodeGen::DominatingValue
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
Definition: EHScopeStack.h:65
clang::ImplicitValueInitExpr
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5510
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:2075
clang::CodeGen::CodeGenFunction::ConditionalEvaluation::begin
void begin(CodeGenFunction &CGF)
Definition: CodeGenFunction.h:1186
clang::CodeGen::CGCXXABI::EmitBadTypeidCall
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
clang::interp::Zero
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:814
clang::CodeGen::CGCXXABI::EmitLoadOfMemberFunctionPointer
virtual CGCallee EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, Address This, llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, const MemberPointerType *MPT)
Load a member function from an object and a member function pointer.
Definition: CGCXXABI.cpp:41
clang::CXXDynamicCastExpr
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:477
clang::CodeGen::CodeGenTypes::arrangeCXXMethodDeclaration
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
Definition: CGCall.cpp:288
clang::CodeGen::CGCUDARuntime::EmitCUDAKernelCallExpr
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGCUDARuntime.cpp:26
clang::InitListExpr::isStringLiteralInit
bool isStringLiteralInit() const
Definition: Expr.cpp:2306
clang::CodeGen::CodeGenFunction::pushCallObjectDeleteCleanup
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
Definition: CGExprCXX.cpp:1865
clang::CXXConstructExpr::CK_Delegating
@ CK_Delegating
Definition: ExprCXX.h:1468
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::CXXDeleteExpr::getOperatorDelete
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2454
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:721
clang::CXXTypeidExpr::getTypeOperand
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Definition: ExprCXX.cpp:161
clang::CXXConstructExpr::getConstructor
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1532
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3359
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:1759
clang::TagDecl::isUnion
bool isUnion() const
Definition: Decl.h:3554
clang::CodeGen::AggValueSlot::IsDestructed
@ IsDestructed
Definition: CGValue.h:551
clang::CodeGen::CGCXXABI::getVBPtrOffsets
virtual std::vector< CharUnits > getVBPtrOffsets(const CXXRecordDecl *RD)
Gets the offsets of all the virtual base pointers in a given class.
Definition: CGCXXABI.cpp:337
EmitDynamicCastToNull
static llvm::Value * EmitDynamicCastToNull(CodeGenFunction &CGF, QualType DestTy)
Definition: CGExprCXX.cpp:2217
clang::CodeGen::CGBuilderTy::getSize
llvm::ConstantInt * getSize(CharUnits N)
Definition: CGBuilder.h:60
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:274
clang::CodeGen::CodeGenFunction::EvaluationOrder::ForceRightToLeft
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1982
clang::CodeGen::CodeGenTypeCache::getPointerSize
CharUnits getPointerSize() const
Definition: CodeGenTypeCache.h:114
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
clang::CodeGen::CodeGenFunction::DeactivateCleanupBlock
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
Definition: CGCleanup.cpp:1283
clang::CodeGen::Address
An aligned address.
Definition: Address.h:74
Base
clang::FunctionDecl::getOverloadedOperator
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3715
clang::CodeGen::CodeGenFunction::SanOpts
SanitizerSet SanOpts
Sanitizers enabled for this function.
Definition: CodeGenFunction.h:518
clang::CodeGen::CodeGenFunction::getEvaluationKind
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Definition: CodeGenFunction.cpp:216
clang::CodeGen::CodeGenFunction::TCK_ConstructorCall
@ TCK_ConstructorCall
Checking the 'this' pointer for a constructor call.
Definition: CodeGenFunction.h:2969
clang::CXXNewExpr::getAllocatedTypeSourceInfo
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition: ExprCXX.h:2236
clang::CodeGen::CodeGenFunction::ConditionalEvaluation
An object to manage conditionally-evaluated expressions.
Definition: CodeGenFunction.h:1179
clang::ast_matchers::arrayType
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
Definition: ASTMatchersInternal.cpp:1034
clang::CharUnits::isNegative
bool isNegative() const
isNegative - Test whether the quantity is less than zero.
Definition: CharUnits.h:125
clang::Qualifiers::OCL_Autoreleasing
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:181
clang::MemberExpr::getMemberDecl
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3247
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:133
clang::interp::Null
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:820
clang::CodeGen::CodeGenFunction::CurGD
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Definition: CodeGenFunction.h:345
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::CodeGen::CodeGenFunction::EmitIgnoredExpr
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
Definition: CGExpr.cpp:190
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:2634
clang::Type::isAlignValT
bool isAlignValT() const
Definition: Type.cpp:2762
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:1148
clang::CodeGen::Address::withAlignment
Address withAlignment(CharUnits NewAlignment) const
Return address with different alignment, but same pointer and element type.
Definition: Address.h:133
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
clang::FunctionDecl::isDestroyingOperatorDelete
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:3261
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1609
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7310
clang::CodeGen::CGBuilderTy::CreateLaunderInvariantGroup
Address CreateLaunderInvariantGroup(Address Addr)
Definition: CGBuilder.h:361
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:790
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
clang::MemberExpr::getBase
Expr * getBase() const
Definition: Expr.h:3241
EnterNewDeleteCleanup
static void EnterNewDeleteCleanup(CodeGenFunction &CGF, const CXXNewExpr *E, Address NewPtr, llvm::Value *AllocSize, CharUnits AllocAlign, const CallArgList &NewArgs)
Enter a cleanup to call 'operator delete' if the initializer in a new-expression throws.
Definition: CGExprCXX.cpp:1484
clang::CodeGen::CodeGenTypes::arrangeCXXMethodCall
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Definition: CGCall.cpp:684
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::CXXMethodDecl::getMethodQualifiers
Qualifiers getMethodQualifiers() const
Definition: DeclCXX.h:2113
clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr
RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, const Expr *Base)
Definition: CGExprCXX.cpp:208
clang::CodeGen::CodeGenTypes::DeriveThisType
CanQualType DeriveThisType(const CXXRecordDecl *RD, const CXXMethodDecl *MD)
Derives the 'this' type for codegen purposes, i.e.
Definition: CGCall.cpp:79
clang::CodeGen::CodeGenFunction::initFullExprCleanup
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
Definition: CodeGenFunction.h:826
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:619
getUsualDeleteParams
static UsualDeleteParams getUsualDeleteParams(const FunctionDecl *FD)
Definition: CGExprCXX.cpp:1357
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::getTargetHooks
const TargetCodeGenInfo & getTargetHooks() const
Definition: CodeGenFunction.h:2026
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6748
clang::CodeGen::CodeGenModule::EmitExplicitCastExprType
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
Definition: CGExpr.cpp:1056
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:93
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
clang::CodeGen::CodeGenFunction::EmitAggregateAssign
void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy)
Emit an aggregate assignment.
Definition: CodeGenFunction.h:2698
clang::CodeGen::RequiredArgs
A class for recording the number of arguments that a function signature requires.
Definition: CGFunctionInfo.h:480
clang::BinaryOperator::getLHS
Expr * getLHS() const
Definition: Expr.h:3856
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:714
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3898
clang::CodeGen::AggValueSlot::IsNotAliased
@ IsNotAliased
Definition: CGValue.h:550
clang::CodeGen::CodeGenTypes::arrangeCXXStructorDeclaration
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
Definition: CGCall.cpp:315
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1876
clang::CodeGen::CodeGenFunction::emitArrayDestroy
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
emitArrayDestroy - Destroys all the elements of the given array, beginning from last to first.
Definition: CGDecl.cpp:2232
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:247
EmitNewDeleteCall
static RValue EmitNewDeleteCall(CodeGenFunction &CGF, const FunctionDecl *CalleeDecl, const FunctionProtoType *CalleeType, const CallArgList &Args)
Emit a call to an operator new or operator delete function, as implicitly created by new-expressions ...
Definition: CGExprCXX.cpp:1305
clang::CXXDeleteExpr
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2415
clang::CodeGen::CodeGenFunction::EmitARCRelease
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
Definition: CGObjC.cpp:2405
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:740
clang::CodeGen::CodeGenModule::GetAddrOfRTTIDescriptor
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
Definition: CodeGenModule.cpp:6564
clang::CodeGen::CodeGenFunction::EmitScalarInit
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition: CGDecl.cpp:774
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::CXXTypeidExpr::isTypeOperand
bool isTypeOperand() const
Definition: ExprCXX.h:875
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::CXXNewExpr::shouldNullCheckAllocation
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
Definition: ExprCXX.cpp:277
clang::CodeGen::CodeGenFunction::EmitCXXMemberPointerCallExpr
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGExprCXX.cpp:431
clang::FunctionDecl::isReplaceableGlobalAllocationFunction
bool isReplaceableGlobalAllocationFunction(Optional< unsigned > *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Definition: Decl.cpp:3182
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:90
clang::CodeGen::CGCallee
All available information about a concrete callee.
Definition: CGCall.h:63
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:2360
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1210
clang::CodeGen::CodeGenFunction::getTypes
CodeGenTypes & getTypes() const
Definition: CodeGenFunction.h:1981
clang::FunctionProtoType::getNumParams
unsigned getNumParams() const
Definition: Type.h:4108
clang::CodeGen::AggValueSlot
An aggregate value slot.
Definition: CGValue.h:491
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:212
clang::CodeGen::EHScopeStack::pushCleanupWithExtra
T * pushCleanupWithExtra(CleanupKind Kind, size_t N, As... A)
Push a cleanup with non-constant storage requirements on the stack.
Definition: EHScopeStack.h:308
clang::CXXDeleteExpr::getDestroyedType
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:287
clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
Definition: CGClass.cpp:2079
clang::CodeGen::NormalAndEHCleanup
@ NormalAndEHCleanup
Definition: EHScopeStack.h:86
clang::CodeGen::AggValueSlot::isZeroed
IsZeroed_t isZeroed() const
Definition: CGValue.h:660
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:2492
clang::CXXRecordDecl::hasTrivialDestructor
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1321
clang::CodeGen::CodeGenFunction::EmitSynthesizedCXXCopyCtor
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
Definition: CGExprCXX.cpp:660
clang::CodeGen::CGCXXABI::shouldTypeidBeNullChecked
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
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:165
clang::Expr::isTemporaryObject
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
Definition: Expr.cpp:3081
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:4869
clang::CXXRecordDecl::getDestructor
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1888
clang::CodeGen::LValueBaseInfo::getAlignmentSource
AlignmentSource getAlignmentSource() const
Definition: CGValue.h:160
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2844
getCXXRecord
static CXXRecordDecl * getCXXRecord(const Expr *E)
Definition: CGExprCXX.cpp:171
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
EmitCXXNewAllocSize
static llvm::Value * EmitCXXNewAllocSize(CodeGenFunction &CGF, const CXXNewExpr *e, unsigned minElements, llvm::Value *&numElements, llvm::Value *&sizeWithoutCookie)
Definition: CGExprCXX.cpp:695
clang::CodeGen::CodeGenFunction::EmitCXXTypeidExpr
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
Definition: CGExprCXX.cpp:2192
clang::CodeGen::AggValueSlot::Overlap_t
Overlap_t
Definition: CGValue.h:553
CGCXXABI.h
clang::CodeGen::AggValueSlot::isIgnored
bool isIgnored() const
Definition: CGValue.h:631
EmitNullBaseClassInitialization
static void EmitNullBaseClassInitialization(CodeGenFunction &CGF, Address DestPtr, const CXXRecordDecl *Base)
Definition: CGExprCXX.cpp:496
clang::CodeGen::CGCXXABI::shouldDynamicCastCallBeNullChecked
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2653
clang::CodeGen::RequiredArgs::forPrototypePlus
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Definition: CGFunctionInfo.h:497
clang::CUDAKernelCallExpr
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:232
clang::Qualifiers::OCL_None
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:164
clang::EnumType::getDecl
EnumDecl * getDecl() const
Definition: Type.h:4680
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:261
clang::interp::This
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:829
clang::CXXConstructExpr::CK_NonVirtualBase
@ CK_NonVirtualBase
Definition: ExprCXX.h:1466
clang::CodeGen::TEK_Scalar
@ TEK_Scalar
Definition: CodeGenFunction.h:107
clang::FunctionDecl::isReservedGlobalPlacementOperator
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:3159
clang::CodeGen::CGCXXABI::EmitDynamicCastToVoid
virtual llvm::Value * EmitDynamicCastToVoid(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy)=0
clang::CodeGen::CodeGenFunction::CFITCK_NVCall
@ CFITCK_NVCall
Definition: CodeGenFunction.h:2296
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2943
clang
Definition: CalledOnceCheck.h:17
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1658
clang::CXXDynamicCastExpr::isAlwaysNull
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null.
Definition: ExprCXX.cpp:767
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:4142
clang::ASTContext::toCharUnitsFromBits
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Definition: ASTContext.cpp:2451
clang::CodeGen::CodeGenTypes::arrangeFreeFunctionCall
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments.
Definition: CGCall.cpp:620
CGCUDARuntime.h
clang::CodeGen::CallArgList::addFrom
void addFrom(const CallArgList &other)
Add all the arguments from another CallArgList to this one.
Definition: CGCall.h:295
clang::CodeGen::AggValueSlot::getAddress
Address getAddress() const
Definition: CGValue.h:627
clang::CXXConstructExpr::CK_VirtualBase
@ CK_VirtualBase
Definition: ExprCXX.h:1467
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3858
std::arg
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40
clang::CXXNewExpr::placement_arguments
llvm::iterator_range< arg_iterator > placement_arguments()
Definition: ExprCXX.h:2361
clang::CodeGen::CodeGenModule::getNaturalTypeAlignment
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
Definition: CodeGenModule.cpp:6730
clang::EnumDecl::getIntegerType
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3788
clang::CodeGen::CodeGenFunction::EmitCXXDeleteExpr
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
Definition: CGExprCXX.cpp:2056
clang::CodeGen::CGCallee::forVirtual
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
Definition: CGCall.h:143
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::CodeGen::CodeGenFunction::EmitCXXOperatorMemberCallExpr
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
Definition: CGExprCXX.cpp:481
clang::CXXRecordDecl::hasDefinition
bool hasDefinition() const
Definition: DeclCXX.h:549
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::CXXNewExpr::getOperatorDelete
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2259
clang::GlobalDecl::getCtorType
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:105
clang::CXXNewExpr::hasInitializer
bool hasInitializer() const
Whether this new-expression has any initializer at all.
Definition: ExprCXX.h:2318
clang::CXXPseudoDestructorExpr::getBase
Expr * getBase() const
Definition: ExprCXX.h:2577
clang::CXXDeleteExpr::getArgument
Expr * getArgument()
Definition: ExprCXX.h:2456
clang::CodeGen::CodeGenFunction::BuildAppleKextVirtualCall
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
BuildAppleKextVirtualCall - This routine is to support gcc's kext ABI making indirect call to virtual...
Definition: CGCXX.cpp:276
clang::CXXMethodDecl::getDevirtualizedMethod
CXXMethodDecl * getDevirtualizedMethod(const Expr *Base, bool IsAppleKext)
If it's possible to devirtualize a call to this method, return the called function.
Definition: DeclCXX.cpp:2198
clang::FunctionDecl::isVariadic
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:2980
clang::Type::isConstantArrayType
bool isConstantArrayType() const
Definition: Type.h:6818
clang::CodeGen::EHScopeStack::stable_begin
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
Definition: EHScopeStack.h:384
clang::SanitizerSet::set
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Definition: Sanitizers.h:164
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:3268
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:103
clang::CodeGen::CodeGenModule::getCUDARuntime
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
Definition: CodeGenModule.h:611
clang::CXXPseudoDestructorExpr::isArrow
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition: ExprCXX.h:2597
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3164
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:1305
clang::CXXRecordDecl::isDynamicClass
bool isDynamicClass() const
Definition: DeclCXX.h:562
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4657
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:3260
clang::CodeGen::CGCXXABI::EmitVirtualDestructorCall
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, Address This, DeleteOrMemberCallExpr E)=0
Emit the ABI-specific virtual destructor call.
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:501
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2764
clang::CodeGen::ConstantEmitter::tryEmitAbstract
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
Definition: CGExprConstant.cpp:1374
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::CodeGen::CodeGenFunction::EmitBuiltinNewDeleteCall
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
Definition: CGExprCXX.cpp:1331
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2663
clang::CodeGen::CodeGenFunction::TCK_MemberCall
@ TCK_MemberCall
Checking the 'this' pointer for a call to a non-static member function.
Definition: CodeGenFunction.h:2967
clang::CodeGen::CodeGenTypes::isZeroInitializable
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Definition: CodeGenTypes.cpp:930
clang::CXXConstructExpr::getArg
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1611
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2524
clang::CXXNewExpr::getArraySize
Optional< Expr * > getArraySize()
This might return None even if isArray() returns true, since there might not be an array size express...
Definition: ExprCXX.h:2267
clang::CodeGen::CodeGenFunction::IsWrappedCXXThis
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
Definition: CGExpr.cpp:1246
clang::CodeGen::CodeGenFunction::AbstractCallee
An abstract representation of regular/ObjC call/message targets.
Definition: CodeGenFunction.h:493
clang::CallExpr::arguments
arg_range arguments()
Definition: Expr.h:3040
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:685
clang::Type::isIntegerType
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7069
clang::Expr
This represents one expression.
Definition: Expr.h:109
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:1026
clang::CodeGen::CodeGenFunction::EmitPointerWithAlignment
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
Definition: CGExpr.cpp:1072
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:1222
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::CodeGen::CodeGenModule::getIntrinsic
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
Definition: CodeGenModule.cpp:5299
commonEmitCXXMemberOrOperatorCall
static MemberCallInfo commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE, CallArgList &Args, CallArgList *RtlArgs)
Definition: CGExprCXX.cpp:36
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4673
clang::CodeGen::CodeGenFunction::isInConditionalBranch
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
Definition: CodeGenFunction.h:1207
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:262
EmitDestroyingObjectDelete
static void EmitDestroyingObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType)
Emit the code for deleting a single object with a destroying operator delete.
Definition: CGExprCXX.cpp:1876
clang::CodeGen::CGBuilderTy::CreateMemSet
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:338
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1872
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:2801
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:544
clang::InitListExpr::getNumInits
unsigned getNumInits() const
Definition: Expr.h:4821
clang::CXXOperatorCallExpr
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:82
clang::CodeGen::CGCXXABI::GetArrayCookieSize
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Returns the extra size required in order to store the array cookie for the given new-expression.
Definition: CGCXXABI.cpp:208
clang::CXXConstructExpr
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1460
clang::CXXConstructExpr::getConstructionKind
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1580
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::EHScopeStack::stable_iterator
A saved depth on the scope stack.
Definition: EHScopeStack.h:101
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1995
clang::CXXConstructExpr::isElidable
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1538
clang::CodeGen::CGCXXABI::EmitDynamicCastCall
virtual llvm::Value * EmitDynamicCastCall(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
clang::CXXMethodDecl::isVirtual
bool isVirtual() const
Definition: DeclCXX.h:2012
clang::ExplicitCastExpr::getTypeAsWritten
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition: Expr.h:3724
clang::CodeGen::CodeGenModule::EmitNullConstantForBase
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type.
Definition: CGExprConstant.cpp:2366
clang::declaresSameEntity
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1207
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:244
clang::CodeGen::CGBuilderTy::CreateLoad
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition: CGBuilder.h:69
clang::CodeGen::CodeGenFunction::EmitBranch
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Definition: CGStmt.cpp:564
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:2083
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1968
clang::CodeGen::CodeGenFunction::ConditionalEvaluation::end
void end(CodeGenFunction &CGF)
Definition: CodeGenFunction.h:1192
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:356
clang::CodeGen::CodeGenFunction::Target
const TargetInfo & Target
Definition: CodeGenFunction.h:262
clang::CodeGen::AggValueSlot::DoesNotOverlap
@ DoesNotOverlap
Definition: CGValue.h:553