clang  16.0.0git
CGExprAgg.cpp
Go to the documentation of this file.
1 //===--- CGExprAgg.cpp - Emit LLVM Code from Aggregate 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 to emit Aggregate Expr nodes as LLVM code.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGCXXABI.h"
14 #include "CGObjCRuntime.h"
15 #include "CodeGenFunction.h"
16 #include "CodeGenModule.h"
17 #include "ConstantEmitter.h"
18 #include "TargetInfo.h"
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/Attr.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/StmtVisitor.h"
24 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/GlobalVariable.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/Intrinsics.h"
29 using namespace clang;
30 using namespace CodeGen;
31 
32 //===----------------------------------------------------------------------===//
33 // Aggregate Expression Emitter
34 //===----------------------------------------------------------------------===//
35 
36 namespace {
37 class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
38  CodeGenFunction &CGF;
39  CGBuilderTy &Builder;
40  AggValueSlot Dest;
41  bool IsResultUnused;
42 
43  AggValueSlot EnsureSlot(QualType T) {
44  if (!Dest.isIgnored()) return Dest;
45  return CGF.CreateAggTemp(T, "agg.tmp.ensured");
46  }
47  void EnsureDest(QualType T) {
48  if (!Dest.isIgnored()) return;
49  Dest = CGF.CreateAggTemp(T, "agg.tmp.ensured");
50  }
51 
52  // Calls `Fn` with a valid return value slot, potentially creating a temporary
53  // to do so. If a temporary is created, an appropriate copy into `Dest` will
54  // be emitted, as will lifetime markers.
55  //
56  // The given function should take a ReturnValueSlot, and return an RValue that
57  // points to said slot.
58  void withReturnValueSlot(const Expr *E,
59  llvm::function_ref<RValue(ReturnValueSlot)> Fn);
60 
61 public:
62  AggExprEmitter(CodeGenFunction &cgf, AggValueSlot Dest, bool IsResultUnused)
63  : CGF(cgf), Builder(CGF.Builder), Dest(Dest),
64  IsResultUnused(IsResultUnused) { }
65 
66  //===--------------------------------------------------------------------===//
67  // Utilities
68  //===--------------------------------------------------------------------===//
69 
70  /// EmitAggLoadOfLValue - Given an expression with aggregate type that
71  /// represents a value lvalue, this method emits the address of the lvalue,
72  /// then loads the result into DestPtr.
73  void EmitAggLoadOfLValue(const Expr *E);
74 
75  enum ExprValueKind {
76  EVK_RValue,
77  EVK_NonRValue
78  };
79 
80  /// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
81  /// SrcIsRValue is true if source comes from an RValue.
82  void EmitFinalDestCopy(QualType type, const LValue &src,
83  ExprValueKind SrcValueKind = EVK_NonRValue);
84  void EmitFinalDestCopy(QualType type, RValue src);
85  void EmitCopy(QualType type, const AggValueSlot &dest,
86  const AggValueSlot &src);
87 
88  void EmitMoveFromReturnSlot(const Expr *E, RValue Src);
89 
90  void EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
91  QualType ArrayQTy, InitListExpr *E);
92 
94  if (CGF.getLangOpts().getGC() && TypeRequiresGCollection(T))
97  }
98 
99  bool TypeRequiresGCollection(QualType T);
100 
101  //===--------------------------------------------------------------------===//
102  // Visitor Methods
103  //===--------------------------------------------------------------------===//
104 
105  void Visit(Expr *E) {
106  ApplyDebugLocation DL(CGF, E);
108  }
109 
110  void VisitStmt(Stmt *S) {
111  CGF.ErrorUnsupported(S, "aggregate expression");
112  }
113  void VisitParenExpr(ParenExpr *PE) { Visit(PE->getSubExpr()); }
114  void VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
115  Visit(GE->getResultExpr());
116  }
117  void VisitCoawaitExpr(CoawaitExpr *E) {
118  CGF.EmitCoawaitExpr(*E, Dest, IsResultUnused);
119  }
120  void VisitCoyieldExpr(CoyieldExpr *E) {
121  CGF.EmitCoyieldExpr(*E, Dest, IsResultUnused);
122  }
123  void VisitUnaryCoawait(UnaryOperator *E) { Visit(E->getSubExpr()); }
124  void VisitUnaryExtension(UnaryOperator *E) { Visit(E->getSubExpr()); }
125  void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E) {
126  return Visit(E->getReplacement());
127  }
128 
129  void VisitConstantExpr(ConstantExpr *E) {
130  EnsureDest(E->getType());
131 
132  if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
133  CGF.EmitAggregateStore(Result, Dest.getAddress(),
135  return;
136  }
137  return Visit(E->getSubExpr());
138  }
139 
140  // l-values.
141  void VisitDeclRefExpr(DeclRefExpr *E) { EmitAggLoadOfLValue(E); }
142  void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
143  void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); }
144  void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); }
145  void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
146  void VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
147  EmitAggLoadOfLValue(E);
148  }
149  void VisitPredefinedExpr(const PredefinedExpr *E) {
150  EmitAggLoadOfLValue(E);
151  }
152 
153  // Operators.
154  void VisitCastExpr(CastExpr *E);
155  void VisitCallExpr(const CallExpr *E);
156  void VisitStmtExpr(const StmtExpr *E);
157  void VisitBinaryOperator(const BinaryOperator *BO);
158  void VisitPointerToDataMemberBinaryOperator(const BinaryOperator *BO);
159  void VisitBinAssign(const BinaryOperator *E);
160  void VisitBinComma(const BinaryOperator *E);
161  void VisitBinCmp(const BinaryOperator *E);
162  void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
163  Visit(E->getSemanticForm());
164  }
165 
166  void VisitObjCMessageExpr(ObjCMessageExpr *E);
167  void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
168  EmitAggLoadOfLValue(E);
169  }
170 
171  void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E);
172  void VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO);
173  void VisitChooseExpr(const ChooseExpr *CE);
174  void VisitInitListExpr(InitListExpr *E);
175  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
176  llvm::Value *outerBegin = nullptr);
177  void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
178  void VisitNoInitExpr(NoInitExpr *E) { } // Do nothing.
179  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
181  Visit(DAE->getExpr());
182  }
183  void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
185  Visit(DIE->getExpr());
186  }
187  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
188  void VisitCXXConstructExpr(const CXXConstructExpr *E);
189  void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E);
190  void VisitLambdaExpr(LambdaExpr *E);
191  void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
192  void VisitExprWithCleanups(ExprWithCleanups *E);
193  void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
194  void VisitCXXTypeidExpr(CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
195  void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
196  void VisitOpaqueValueExpr(OpaqueValueExpr *E);
197 
198  void VisitPseudoObjectExpr(PseudoObjectExpr *E) {
199  if (E->isGLValue()) {
200  LValue LV = CGF.EmitPseudoObjectLValue(E);
201  return EmitFinalDestCopy(E->getType(), LV);
202  }
203 
204  CGF.EmitPseudoObjectRValue(E, EnsureSlot(E->getType()));
205  }
206 
207  void VisitVAArgExpr(VAArgExpr *E);
208 
209  void EmitInitializationToLValue(Expr *E, LValue Address);
210  void EmitNullInitializationToLValue(LValue Address);
211  // case Expr::ChooseExprClass:
212  void VisitCXXThrowExpr(const CXXThrowExpr *E) { CGF.EmitCXXThrowExpr(E); }
213  void VisitAtomicExpr(AtomicExpr *E) {
214  RValue Res = CGF.EmitAtomicExpr(E);
215  EmitFinalDestCopy(E->getType(), Res);
216  }
217 };
218 } // end anonymous namespace.
219 
220 //===----------------------------------------------------------------------===//
221 // Utilities
222 //===----------------------------------------------------------------------===//
223 
224 /// EmitAggLoadOfLValue - Given an expression with aggregate type that
225 /// represents a value lvalue, this method emits the address of the lvalue,
226 /// then loads the result into DestPtr.
227 void AggExprEmitter::EmitAggLoadOfLValue(const Expr *E) {
228  LValue LV = CGF.EmitLValue(E);
229 
230  // If the type of the l-value is atomic, then do an atomic load.
231  if (LV.getType()->isAtomicType() || CGF.LValueIsSuitableForInlineAtomic(LV)) {
232  CGF.EmitAtomicLoad(LV, E->getExprLoc(), Dest);
233  return;
234  }
235 
236  EmitFinalDestCopy(E->getType(), LV);
237 }
238 
239 /// True if the given aggregate type requires special GC API calls.
240 bool AggExprEmitter::TypeRequiresGCollection(QualType T) {
241  // Only record types have members that might require garbage collection.
242  const RecordType *RecordTy = T->getAs<RecordType>();
243  if (!RecordTy) return false;
244 
245  // Don't mess with non-trivial C++ types.
246  RecordDecl *Record = RecordTy->getDecl();
247  if (isa<CXXRecordDecl>(Record) &&
248  (cast<CXXRecordDecl>(Record)->hasNonTrivialCopyConstructor() ||
249  !cast<CXXRecordDecl>(Record)->hasTrivialDestructor()))
250  return false;
251 
252  // Check whether the type has an object member.
253  return Record->hasObjectMember();
254 }
255 
256 void AggExprEmitter::withReturnValueSlot(
257  const Expr *E, llvm::function_ref<RValue(ReturnValueSlot)> EmitCall) {
258  QualType RetTy = E->getType();
259  bool RequiresDestruction =
260  !Dest.isExternallyDestructed() &&
262 
263  // If it makes no observable difference, save a memcpy + temporary.
264  //
265  // We need to always provide our own temporary if destruction is required.
266  // Otherwise, EmitCall will emit its own, notice that it's "unused", and end
267  // its lifetime before we have the chance to emit a proper destructor call.
268  bool UseTemp = Dest.isPotentiallyAliased() || Dest.requiresGCollection() ||
269  (RequiresDestruction && !Dest.getAddress().isValid());
270 
271  Address RetAddr = Address::invalid();
272  Address RetAllocaAddr = Address::invalid();
273 
274  EHScopeStack::stable_iterator LifetimeEndBlock;
275  llvm::Value *LifetimeSizePtr = nullptr;
276  llvm::IntrinsicInst *LifetimeStartInst = nullptr;
277  if (!UseTemp) {
278  RetAddr = Dest.getAddress();
279  } else {
280  RetAddr = CGF.CreateMemTemp(RetTy, "tmp", &RetAllocaAddr);
281  llvm::TypeSize Size =
282  CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
283  LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAllocaAddr.getPointer());
284  if (LifetimeSizePtr) {
285  LifetimeStartInst =
286  cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
287  assert(LifetimeStartInst->getIntrinsicID() ==
288  llvm::Intrinsic::lifetime_start &&
289  "Last insertion wasn't a lifetime.start?");
290 
292  NormalEHLifetimeMarker, RetAllocaAddr, LifetimeSizePtr);
293  LifetimeEndBlock = CGF.EHStack.stable_begin();
294  }
295  }
296 
297  RValue Src =
298  EmitCall(ReturnValueSlot(RetAddr, Dest.isVolatile(), IsResultUnused,
299  Dest.isExternallyDestructed()));
300 
301  if (!UseTemp)
302  return;
303 
304  assert(Dest.isIgnored() || Dest.getPointer() != Src.getAggregatePointer());
305  EmitFinalDestCopy(E->getType(), Src);
306 
307  if (!RequiresDestruction && LifetimeStartInst) {
308  // If there's no dtor to run, the copy was the last use of our temporary.
309  // Since we're not guaranteed to be in an ExprWithCleanups, clean up
310  // eagerly.
311  CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
312  CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAllocaAddr.getPointer());
313  }
314 }
315 
316 /// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
317 void AggExprEmitter::EmitFinalDestCopy(QualType type, RValue src) {
318  assert(src.isAggregate() && "value must be aggregate value!");
319  LValue srcLV = CGF.MakeAddrLValue(src.getAggregateAddress(), type);
320  EmitFinalDestCopy(type, srcLV, EVK_RValue);
321 }
322 
323 /// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
324 void AggExprEmitter::EmitFinalDestCopy(QualType type, const LValue &src,
325  ExprValueKind SrcValueKind) {
326  // If Dest is ignored, then we're evaluating an aggregate expression
327  // in a context that doesn't care about the result. Note that loads
328  // from volatile l-values force the existence of a non-ignored
329  // destination.
330  if (Dest.isIgnored())
331  return;
332 
333  // Copy non-trivial C structs here.
334  LValue DstLV = CGF.MakeAddrLValue(
335  Dest.getAddress(), Dest.isVolatile() ? type.withVolatile() : type);
336 
337  if (SrcValueKind == EVK_RValue) {
338  if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
339  if (Dest.isPotentiallyAliased())
340  CGF.callCStructMoveAssignmentOperator(DstLV, src);
341  else
342  CGF.callCStructMoveConstructor(DstLV, src);
343  return;
344  }
345  } else {
346  if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
347  if (Dest.isPotentiallyAliased())
348  CGF.callCStructCopyAssignmentOperator(DstLV, src);
349  else
350  CGF.callCStructCopyConstructor(DstLV, src);
351  return;
352  }
353  }
354 
356  src, CGF, AggValueSlot::IsDestructed, needsGC(type),
358  EmitCopy(type, Dest, srcAgg);
359 }
360 
361 /// Perform a copy from the source into the destination.
362 ///
363 /// \param type - the type of the aggregate being copied; qualifiers are
364 /// ignored
365 void AggExprEmitter::EmitCopy(QualType type, const AggValueSlot &dest,
366  const AggValueSlot &src) {
367  if (dest.requiresGCollection()) {
368  CharUnits sz = dest.getPreferredSize(CGF.getContext(), type);
369  llvm::Value *size = llvm::ConstantInt::get(CGF.SizeTy, sz.getQuantity());
371  dest.getAddress(),
372  src.getAddress(),
373  size);
374  return;
375  }
376 
377  // If the result of the assignment is used, copy the LHS there also.
378  // It's volatile if either side is. Use the minimum alignment of
379  // the two sides.
380  LValue DestLV = CGF.MakeAddrLValue(dest.getAddress(), type);
381  LValue SrcLV = CGF.MakeAddrLValue(src.getAddress(), type);
382  CGF.EmitAggregateCopy(DestLV, SrcLV, type, dest.mayOverlap(),
383  dest.isVolatile() || src.isVolatile());
384 }
385 
386 /// Emit the initializer for a std::initializer_list initialized with a
387 /// real initializer list.
388 void
389 AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
390  // Emit an array containing the elements. The array is externally destructed
391  // if the std::initializer_list object is.
392  ASTContext &Ctx = CGF.getContext();
393  LValue Array = CGF.EmitLValue(E->getSubExpr());
394  assert(Array.isSimple() && "initializer_list array not a simple lvalue");
395  Address ArrayPtr = Array.getAddress(CGF);
396 
399  assert(ArrayType && "std::initializer_list constructed from non-array");
400 
401  // FIXME: Perform the checks on the field types in SemaInit.
402  RecordDecl *Record = E->getType()->castAs<RecordType>()->getDecl();
404  if (Field == Record->field_end()) {
405  CGF.ErrorUnsupported(E, "weird std::initializer_list");
406  return;
407  }
408 
409  // Start pointer.
410  if (!Field->getType()->isPointerType() ||
411  !Ctx.hasSameType(Field->getType()->getPointeeType(),
413  CGF.ErrorUnsupported(E, "weird std::initializer_list");
414  return;
415  }
416 
417  AggValueSlot Dest = EnsureSlot(E->getType());
418  LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), E->getType());
419  LValue Start = CGF.EmitLValueForFieldInitialization(DestLV, *Field);
420  llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0);
421  llvm::Value *IdxStart[] = { Zero, Zero };
422  llvm::Value *ArrayStart = Builder.CreateInBoundsGEP(
423  ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxStart, "arraystart");
424  CGF.EmitStoreThroughLValue(RValue::get(ArrayStart), Start);
425  ++Field;
426 
427  if (Field == Record->field_end()) {
428  CGF.ErrorUnsupported(E, "weird std::initializer_list");
429  return;
430  }
431 
432  llvm::Value *Size = Builder.getInt(ArrayType->getSize());
433  LValue EndOrLength = CGF.EmitLValueForFieldInitialization(DestLV, *Field);
434  if (Field->getType()->isPointerType() &&
435  Ctx.hasSameType(Field->getType()->getPointeeType(),
437  // End pointer.
438  llvm::Value *IdxEnd[] = { Zero, Size };
439  llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP(
440  ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxEnd, "arrayend");
441  CGF.EmitStoreThroughLValue(RValue::get(ArrayEnd), EndOrLength);
442  } else if (Ctx.hasSameType(Field->getType(), Ctx.getSizeType())) {
443  // Length.
444  CGF.EmitStoreThroughLValue(RValue::get(Size), EndOrLength);
445  } else {
446  CGF.ErrorUnsupported(E, "weird std::initializer_list");
447  return;
448  }
449 }
450 
451 /// Determine if E is a trivial array filler, that is, one that is
452 /// equivalent to zero-initialization.
453 static bool isTrivialFiller(Expr *E) {
454  if (!E)
455  return true;
456 
457  if (isa<ImplicitValueInitExpr>(E))
458  return true;
459 
460  if (auto *ILE = dyn_cast<InitListExpr>(E)) {
461  if (ILE->getNumInits())
462  return false;
463  return isTrivialFiller(ILE->getArrayFiller());
464  }
465 
466  if (auto *Cons = dyn_cast_or_null<CXXConstructExpr>(E))
467  return Cons->getConstructor()->isDefaultConstructor() &&
468  Cons->getConstructor()->isTrivial();
469 
470  // FIXME: Are there other cases where we can avoid emitting an initializer?
471  return false;
472 }
473 
474 /// Emit initialization of an array from an initializer list.
475 void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
476  QualType ArrayQTy, InitListExpr *E) {
477  uint64_t NumInitElements = E->getNumInits();
478 
479  uint64_t NumArrayElements = AType->getNumElements();
480  assert(NumInitElements <= NumArrayElements);
481 
482  QualType elementType =
483  CGF.getContext().getAsArrayType(ArrayQTy)->getElementType();
484 
485  // DestPtr is an array*. Construct an elementType* by drilling
486  // down a level.
487  llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
488  llvm::Value *indices[] = { zero, zero };
489  llvm::Value *begin = Builder.CreateInBoundsGEP(
490  DestPtr.getElementType(), DestPtr.getPointer(), indices,
491  "arrayinit.begin");
492 
493  CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
494  CharUnits elementAlign =
495  DestPtr.getAlignment().alignmentOfArrayElement(elementSize);
496  llvm::Type *llvmElementType = CGF.ConvertTypeForMem(elementType);
497 
498  // Consider initializing the array by copying from a global. For this to be
499  // more efficient than per-element initialization, the size of the elements
500  // with explicit initializers should be large enough.
501  if (NumInitElements * elementSize.getQuantity() > 16 &&
502  elementType.isTriviallyCopyableType(CGF.getContext())) {
503  CodeGen::CodeGenModule &CGM = CGF.CGM;
505  LangAS AS = ArrayQTy.getAddressSpace();
506  if (llvm::Constant *C = Emitter.tryEmitForInitializer(E, AS, ArrayQTy)) {
507  auto GV = new llvm::GlobalVariable(
508  CGM.getModule(), C->getType(),
509  CGM.isTypeConstant(ArrayQTy, /* ExcludeCtorDtor= */ true),
510  llvm::GlobalValue::PrivateLinkage, C, "constinit",
511  /* InsertBefore= */ nullptr, llvm::GlobalVariable::NotThreadLocal,
513  Emitter.finalize(GV);
514  CharUnits Align = CGM.getContext().getTypeAlignInChars(ArrayQTy);
515  GV->setAlignment(Align.getAsAlign());
516  Address GVAddr(GV, GV->getValueType(), Align);
517  EmitFinalDestCopy(ArrayQTy, CGF.MakeAddrLValue(GVAddr, ArrayQTy));
518  return;
519  }
520  }
521 
522  // Exception safety requires us to destroy all the
523  // already-constructed members if an initializer throws.
524  // For that, we'll need an EH cleanup.
525  QualType::DestructionKind dtorKind = elementType.isDestructedType();
526  Address endOfInit = Address::invalid();
528  llvm::Instruction *cleanupDominator = nullptr;
529  if (CGF.needsEHCleanup(dtorKind)) {
530  // In principle we could tell the cleanup where we are more
531  // directly, but the control flow can get so varied here that it
532  // would actually be quite complex. Therefore we go through an
533  // alloca.
534  endOfInit = CGF.CreateTempAlloca(begin->getType(), CGF.getPointerAlign(),
535  "arrayinit.endOfInit");
536  cleanupDominator = Builder.CreateStore(begin, endOfInit);
537  CGF.pushIrregularPartialArrayCleanup(begin, endOfInit, elementType,
538  elementAlign,
539  CGF.getDestroyer(dtorKind));
540  cleanup = CGF.EHStack.stable_begin();
541 
542  // Otherwise, remember that we didn't need a cleanup.
543  } else {
544  dtorKind = QualType::DK_none;
545  }
546 
547  llvm::Value *one = llvm::ConstantInt::get(CGF.SizeTy, 1);
548 
549  // The 'current element to initialize'. The invariants on this
550  // variable are complicated. Essentially, after each iteration of
551  // the loop, it points to the last initialized element, except
552  // that it points to the beginning of the array before any
553  // elements have been initialized.
554  llvm::Value *element = begin;
555 
556  // Emit the explicit initializers.
557  for (uint64_t i = 0; i != NumInitElements; ++i) {
558  // Advance to the next element.
559  if (i > 0) {
560  element = Builder.CreateInBoundsGEP(
561  llvmElementType, element, one, "arrayinit.element");
562 
563  // Tell the cleanup that it needs to destroy up to this
564  // element. TODO: some of these stores can be trivially
565  // observed to be unnecessary.
566  if (endOfInit.isValid()) Builder.CreateStore(element, endOfInit);
567  }
568 
569  LValue elementLV = CGF.MakeAddrLValue(
570  Address(element, llvmElementType, elementAlign), elementType);
571  EmitInitializationToLValue(E->getInit(i), elementLV);
572  }
573 
574  // Check whether there's a non-trivial array-fill expression.
575  Expr *filler = E->getArrayFiller();
576  bool hasTrivialFiller = isTrivialFiller(filler);
577 
578  // Any remaining elements need to be zero-initialized, possibly
579  // using the filler expression. We can skip this if the we're
580  // emitting to zeroed memory.
581  if (NumInitElements != NumArrayElements &&
582  !(Dest.isZeroed() && hasTrivialFiller &&
583  CGF.getTypes().isZeroInitializable(elementType))) {
584 
585  // Use an actual loop. This is basically
586  // do { *array++ = filler; } while (array != end);
587 
588  // Advance to the start of the rest of the array.
589  if (NumInitElements) {
590  element = Builder.CreateInBoundsGEP(
591  llvmElementType, element, one, "arrayinit.start");
592  if (endOfInit.isValid()) Builder.CreateStore(element, endOfInit);
593  }
594 
595  // Compute the end of the array.
596  llvm::Value *end = Builder.CreateInBoundsGEP(
597  llvmElementType, begin,
598  llvm::ConstantInt::get(CGF.SizeTy, NumArrayElements), "arrayinit.end");
599 
600  llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
601  llvm::BasicBlock *bodyBB = CGF.createBasicBlock("arrayinit.body");
602 
603  // Jump into the body.
604  CGF.EmitBlock(bodyBB);
605  llvm::PHINode *currentElement =
606  Builder.CreatePHI(element->getType(), 2, "arrayinit.cur");
607  currentElement->addIncoming(element, entryBB);
608 
609  // Emit the actual filler expression.
610  {
611  // C++1z [class.temporary]p5:
612  // when a default constructor is called to initialize an element of
613  // an array with no corresponding initializer [...] the destruction of
614  // every temporary created in a default argument is sequenced before
615  // the construction of the next array element, if any
616  CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
617  LValue elementLV = CGF.MakeAddrLValue(
618  Address(currentElement, llvmElementType, elementAlign), elementType);
619  if (filler)
620  EmitInitializationToLValue(filler, elementLV);
621  else
622  EmitNullInitializationToLValue(elementLV);
623  }
624 
625  // Move on to the next element.
626  llvm::Value *nextElement = Builder.CreateInBoundsGEP(
627  llvmElementType, currentElement, one, "arrayinit.next");
628 
629  // Tell the EH cleanup that we finished with the last element.
630  if (endOfInit.isValid()) Builder.CreateStore(nextElement, endOfInit);
631 
632  // Leave the loop if we're done.
633  llvm::Value *done = Builder.CreateICmpEQ(nextElement, end,
634  "arrayinit.done");
635  llvm::BasicBlock *endBB = CGF.createBasicBlock("arrayinit.end");
636  Builder.CreateCondBr(done, endBB, bodyBB);
637  currentElement->addIncoming(nextElement, Builder.GetInsertBlock());
638 
639  CGF.EmitBlock(endBB);
640  }
641 
642  // Leave the partial-array cleanup if we entered one.
643  if (dtorKind) CGF.DeactivateCleanupBlock(cleanup, cleanupDominator);
644 }
645 
646 //===----------------------------------------------------------------------===//
647 // Visitor Methods
648 //===----------------------------------------------------------------------===//
649 
650 void AggExprEmitter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E){
651  Visit(E->getSubExpr());
652 }
653 
654 void AggExprEmitter::VisitOpaqueValueExpr(OpaqueValueExpr *e) {
655  // If this is a unique OVE, just visit its source expression.
656  if (e->isUnique())
657  Visit(e->getSourceExpr());
658  else
659  EmitFinalDestCopy(e->getType(), CGF.getOrCreateOpaqueLValueMapping(e));
660 }
661 
662 void
663 AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
664  if (Dest.isPotentiallyAliased() &&
665  E->getType().isPODType(CGF.getContext())) {
666  // For a POD type, just emit a load of the lvalue + a copy, because our
667  // compound literal might alias the destination.
668  EmitAggLoadOfLValue(E);
669  return;
670  }
671 
672  AggValueSlot Slot = EnsureSlot(E->getType());
673 
674  // Block-scope compound literals are destroyed at the end of the enclosing
675  // scope in C.
676  bool Destruct =
677  !CGF.getLangOpts().CPlusPlus && !Slot.isExternallyDestructed();
678  if (Destruct)
680 
681  CGF.EmitAggExpr(E->getInitializer(), Slot);
682 
683  if (Destruct)
684  if (QualType::DestructionKind DtorKind = E->getType().isDestructedType())
686  CGF.getCleanupKind(DtorKind), Slot.getAddress(), E->getType(),
687  CGF.getDestroyer(DtorKind), DtorKind & EHCleanup);
688 }
689 
690 /// Attempt to look through various unimportant expressions to find a
691 /// cast of the given kind.
692 static Expr *findPeephole(Expr *op, CastKind kind, const ASTContext &ctx) {
693  op = op->IgnoreParenNoopCasts(ctx);
694  if (auto castE = dyn_cast<CastExpr>(op)) {
695  if (castE->getCastKind() == kind)
696  return castE->getSubExpr();
697  }
698  return nullptr;
699 }
700 
701 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
702  if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
703  CGF.CGM.EmitExplicitCastExprType(ECE, &CGF);
704  switch (E->getCastKind()) {
705  case CK_Dynamic: {
706  // FIXME: Can this actually happen? We have no test coverage for it.
707  assert(isa<CXXDynamicCastExpr>(E) && "CK_Dynamic without a dynamic_cast?");
708  LValue LV = CGF.EmitCheckedLValue(E->getSubExpr(),
710  // FIXME: Do we also need to handle property references here?
711  if (LV.isSimple())
712  CGF.EmitDynamicCast(LV.getAddress(CGF), cast<CXXDynamicCastExpr>(E));
713  else
714  CGF.CGM.ErrorUnsupported(E, "non-simple lvalue dynamic_cast");
715 
716  if (!Dest.isIgnored())
717  CGF.CGM.ErrorUnsupported(E, "lvalue dynamic_cast with a destination");
718  break;
719  }
720 
721  case CK_ToUnion: {
722  // Evaluate even if the destination is ignored.
723  if (Dest.isIgnored()) {
725  /*ignoreResult=*/true);
726  break;
727  }
728 
729  // GCC union extension
730  QualType Ty = E->getSubExpr()->getType();
731  Address CastPtr =
732  Builder.CreateElementBitCast(Dest.getAddress(), CGF.ConvertType(Ty));
733  EmitInitializationToLValue(E->getSubExpr(),
734  CGF.MakeAddrLValue(CastPtr, Ty));
735  break;
736  }
737 
738  case CK_LValueToRValueBitCast: {
739  if (Dest.isIgnored()) {
741  /*ignoreResult=*/true);
742  break;
743  }
744 
745  LValue SourceLV = CGF.EmitLValue(E->getSubExpr());
746  Address SourceAddress =
747  Builder.CreateElementBitCast(SourceLV.getAddress(CGF), CGF.Int8Ty);
748  Address DestAddress =
749  Builder.CreateElementBitCast(Dest.getAddress(), CGF.Int8Ty);
750  llvm::Value *SizeVal = llvm::ConstantInt::get(
751  CGF.SizeTy,
753  Builder.CreateMemCpy(DestAddress, SourceAddress, SizeVal);
754  break;
755  }
756 
757  case CK_DerivedToBase:
758  case CK_BaseToDerived:
759  case CK_UncheckedDerivedToBase: {
760  llvm_unreachable("cannot perform hierarchy conversion in EmitAggExpr: "
761  "should have been unpacked before we got here");
762  }
763 
764  case CK_NonAtomicToAtomic:
765  case CK_AtomicToNonAtomic: {
766  bool isToAtomic = (E->getCastKind() == CK_NonAtomicToAtomic);
767 
768  // Determine the atomic and value types.
770  QualType valueType = E->getType();
771  if (isToAtomic) std::swap(atomicType, valueType);
772 
773  assert(atomicType->isAtomicType());
774  assert(CGF.getContext().hasSameUnqualifiedType(valueType,
775  atomicType->castAs<AtomicType>()->getValueType()));
776 
777  // Just recurse normally if we're ignoring the result or the
778  // atomic type doesn't change representation.
779  if (Dest.isIgnored() || !CGF.CGM.isPaddedAtomicType(atomicType)) {
780  return Visit(E->getSubExpr());
781  }
782 
783  CastKind peepholeTarget =
784  (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
785 
786  // These two cases are reverses of each other; try to peephole them.
787  if (Expr *op =
788  findPeephole(E->getSubExpr(), peepholeTarget, CGF.getContext())) {
789  assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
790  E->getType()) &&
791  "peephole significantly changed types?");
792  return Visit(op);
793  }
794 
795  // If we're converting an r-value of non-atomic type to an r-value
796  // of atomic type, just emit directly into the relevant sub-object.
797  if (isToAtomic) {
798  AggValueSlot valueDest = Dest;
799  if (!valueDest.isIgnored() && CGF.CGM.isPaddedAtomicType(atomicType)) {
800  // Zero-initialize. (Strictly speaking, we only need to initialize
801  // the padding at the end, but this is simpler.)
802  if (!Dest.isZeroed())
804 
805  // Build a GEP to refer to the subobject.
806  Address valueAddr =
807  CGF.Builder.CreateStructGEP(valueDest.getAddress(), 0);
808  valueDest = AggValueSlot::forAddr(valueAddr,
809  valueDest.getQualifiers(),
810  valueDest.isExternallyDestructed(),
811  valueDest.requiresGCollection(),
812  valueDest.isPotentiallyAliased(),
815  }
816 
817  CGF.EmitAggExpr(E->getSubExpr(), valueDest);
818  return;
819  }
820 
821  // Otherwise, we're converting an atomic type to a non-atomic type.
822  // Make an atomic temporary, emit into that, and then copy the value out.
823  AggValueSlot atomicSlot =
824  CGF.CreateAggTemp(atomicType, "atomic-to-nonatomic.temp");
825  CGF.EmitAggExpr(E->getSubExpr(), atomicSlot);
826 
827  Address valueAddr = Builder.CreateStructGEP(atomicSlot.getAddress(), 0);
828  RValue rvalue = RValue::getAggregate(valueAddr, atomicSlot.isVolatile());
829  return EmitFinalDestCopy(valueType, rvalue);
830  }
831  case CK_AddressSpaceConversion:
832  return Visit(E->getSubExpr());
833 
834  case CK_LValueToRValue:
835  // If we're loading from a volatile type, force the destination
836  // into existence.
837  if (E->getSubExpr()->getType().isVolatileQualified()) {
838  bool Destruct =
839  !Dest.isExternallyDestructed() &&
841  if (Destruct)
843  EnsureDest(E->getType());
844  Visit(E->getSubExpr());
845 
846  if (Destruct)
848  E->getType());
849 
850  return;
851  }
852 
853  [[fallthrough]];
854 
855 
856  case CK_NoOp:
857  case CK_UserDefinedConversion:
858  case CK_ConstructorConversion:
860  E->getType()) &&
861  "Implicit cast types must be compatible");
862  Visit(E->getSubExpr());
863  break;
864 
865  case CK_LValueBitCast:
866  llvm_unreachable("should not be emitting lvalue bitcast as rvalue");
867 
868  case CK_Dependent:
869  case CK_BitCast:
870  case CK_ArrayToPointerDecay:
871  case CK_FunctionToPointerDecay:
872  case CK_NullToPointer:
873  case CK_NullToMemberPointer:
874  case CK_BaseToDerivedMemberPointer:
875  case CK_DerivedToBaseMemberPointer:
876  case CK_MemberPointerToBoolean:
877  case CK_ReinterpretMemberPointer:
878  case CK_IntegralToPointer:
879  case CK_PointerToIntegral:
880  case CK_PointerToBoolean:
881  case CK_ToVoid:
882  case CK_VectorSplat:
883  case CK_IntegralCast:
884  case CK_BooleanToSignedIntegral:
885  case CK_IntegralToBoolean:
886  case CK_IntegralToFloating:
887  case CK_FloatingToIntegral:
888  case CK_FloatingToBoolean:
889  case CK_FloatingCast:
890  case CK_CPointerToObjCPointerCast:
891  case CK_BlockPointerToObjCPointerCast:
892  case CK_AnyPointerToBlockPointerCast:
893  case CK_ObjCObjectLValueCast:
894  case CK_FloatingRealToComplex:
895  case CK_FloatingComplexToReal:
896  case CK_FloatingComplexToBoolean:
897  case CK_FloatingComplexCast:
898  case CK_FloatingComplexToIntegralComplex:
899  case CK_IntegralRealToComplex:
900  case CK_IntegralComplexToReal:
901  case CK_IntegralComplexToBoolean:
902  case CK_IntegralComplexCast:
903  case CK_IntegralComplexToFloatingComplex:
904  case CK_ARCProduceObject:
905  case CK_ARCConsumeObject:
906  case CK_ARCReclaimReturnedObject:
907  case CK_ARCExtendBlockObject:
908  case CK_CopyAndAutoreleaseBlockObject:
909  case CK_BuiltinFnToFnPtr:
910  case CK_ZeroToOCLOpaqueType:
911  case CK_MatrixCast:
912 
913  case CK_IntToOCLSampler:
914  case CK_FloatingToFixedPoint:
915  case CK_FixedPointToFloating:
916  case CK_FixedPointCast:
917  case CK_FixedPointToBoolean:
918  case CK_FixedPointToIntegral:
919  case CK_IntegralToFixedPoint:
920  llvm_unreachable("cast kind invalid for aggregate types");
921  }
922 }
923 
924 void AggExprEmitter::VisitCallExpr(const CallExpr *E) {
925  if (E->getCallReturnType(CGF.getContext())->isReferenceType()) {
926  EmitAggLoadOfLValue(E);
927  return;
928  }
929 
930  withReturnValueSlot(E, [&](ReturnValueSlot Slot) {
931  return CGF.EmitCallExpr(E, Slot);
932  });
933 }
934 
935 void AggExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
936  withReturnValueSlot(E, [&](ReturnValueSlot Slot) {
937  return CGF.EmitObjCMessageExpr(E, Slot);
938  });
939 }
940 
941 void AggExprEmitter::VisitBinComma(const BinaryOperator *E) {
942  CGF.EmitIgnoredExpr(E->getLHS());
943  Visit(E->getRHS());
944 }
945 
946 void AggExprEmitter::VisitStmtExpr(const StmtExpr *E) {
948  CGF.EmitCompoundStmt(*E->getSubStmt(), true, Dest);
949 }
950 
955 };
956 
957 static llvm::Value *EmitCompare(CGBuilderTy &Builder, CodeGenFunction &CGF,
958  const BinaryOperator *E, llvm::Value *LHS,
959  llvm::Value *RHS, CompareKind Kind,
960  const char *NameSuffix = "") {
961  QualType ArgTy = E->getLHS()->getType();
962  if (const ComplexType *CT = ArgTy->getAs<ComplexType>())
963  ArgTy = CT->getElementType();
964 
965  if (const auto *MPT = ArgTy->getAs<MemberPointerType>()) {
966  assert(Kind == CK_Equal &&
967  "member pointers may only be compared for equality");
969  CGF, LHS, RHS, MPT, /*IsInequality*/ false);
970  }
971 
972  // Compute the comparison instructions for the specified comparison kind.
973  struct CmpInstInfo {
974  const char *Name;
975  llvm::CmpInst::Predicate FCmp;
976  llvm::CmpInst::Predicate SCmp;
977  llvm::CmpInst::Predicate UCmp;
978  };
979  CmpInstInfo InstInfo = [&]() -> CmpInstInfo {
980  using FI = llvm::FCmpInst;
981  using II = llvm::ICmpInst;
982  switch (Kind) {
983  case CK_Less:
984  return {"cmp.lt", FI::FCMP_OLT, II::ICMP_SLT, II::ICMP_ULT};
985  case CK_Greater:
986  return {"cmp.gt", FI::FCMP_OGT, II::ICMP_SGT, II::ICMP_UGT};
987  case CK_Equal:
988  return {"cmp.eq", FI::FCMP_OEQ, II::ICMP_EQ, II::ICMP_EQ};
989  }
990  llvm_unreachable("Unrecognised CompareKind enum");
991  }();
992 
993  if (ArgTy->hasFloatingRepresentation())
994  return Builder.CreateFCmp(InstInfo.FCmp, LHS, RHS,
995  llvm::Twine(InstInfo.Name) + NameSuffix);
996  if (ArgTy->isIntegralOrEnumerationType() || ArgTy->isPointerType()) {
997  auto Inst =
998  ArgTy->hasSignedIntegerRepresentation() ? InstInfo.SCmp : InstInfo.UCmp;
999  return Builder.CreateICmp(Inst, LHS, RHS,
1000  llvm::Twine(InstInfo.Name) + NameSuffix);
1001  }
1002 
1003  llvm_unreachable("unsupported aggregate binary expression should have "
1004  "already been handled");
1005 }
1006 
1007 void AggExprEmitter::VisitBinCmp(const BinaryOperator *E) {
1008  using llvm::BasicBlock;
1009  using llvm::PHINode;
1010  using llvm::Value;
1011  assert(CGF.getContext().hasSameType(E->getLHS()->getType(),
1012  E->getRHS()->getType()));
1013  const ComparisonCategoryInfo &CmpInfo =
1015  assert(CmpInfo.Record->isTriviallyCopyable() &&
1016  "cannot copy non-trivially copyable aggregate");
1017 
1018  QualType ArgTy = E->getLHS()->getType();
1019 
1020  if (!ArgTy->isIntegralOrEnumerationType() && !ArgTy->isRealFloatingType() &&
1021  !ArgTy->isNullPtrType() && !ArgTy->isPointerType() &&
1022  !ArgTy->isMemberPointerType() && !ArgTy->isAnyComplexType()) {
1023  return CGF.ErrorUnsupported(E, "aggregate three-way comparison");
1024  }
1025  bool IsComplex = ArgTy->isAnyComplexType();
1026 
1027  // Evaluate the operands to the expression and extract their values.
1028  auto EmitOperand = [&](Expr *E) -> std::pair<Value *, Value *> {
1029  RValue RV = CGF.EmitAnyExpr(E);
1030  if (RV.isScalar())
1031  return {RV.getScalarVal(), nullptr};
1032  if (RV.isAggregate())
1033  return {RV.getAggregatePointer(), nullptr};
1034  assert(RV.isComplex());
1035  return RV.getComplexVal();
1036  };
1037  auto LHSValues = EmitOperand(E->getLHS()),
1038  RHSValues = EmitOperand(E->getRHS());
1039 
1040  auto EmitCmp = [&](CompareKind K) {
1041  Value *Cmp = EmitCompare(Builder, CGF, E, LHSValues.first, RHSValues.first,
1042  K, IsComplex ? ".r" : "");
1043  if (!IsComplex)
1044  return Cmp;
1045  assert(K == CompareKind::CK_Equal);
1046  Value *CmpImag = EmitCompare(Builder, CGF, E, LHSValues.second,
1047  RHSValues.second, K, ".i");
1048  return Builder.CreateAnd(Cmp, CmpImag, "and.eq");
1049  };
1050  auto EmitCmpRes = [&](const ComparisonCategoryInfo::ValueInfo *VInfo) {
1051  return Builder.getInt(VInfo->getIntValue());
1052  };
1053 
1054  Value *Select;
1055  if (ArgTy->isNullPtrType()) {
1056  Select = EmitCmpRes(CmpInfo.getEqualOrEquiv());
1057  } else if (!CmpInfo.isPartial()) {
1058  Value *SelectOne =
1059  Builder.CreateSelect(EmitCmp(CK_Less), EmitCmpRes(CmpInfo.getLess()),
1060  EmitCmpRes(CmpInfo.getGreater()), "sel.lt");
1061  Select = Builder.CreateSelect(EmitCmp(CK_Equal),
1062  EmitCmpRes(CmpInfo.getEqualOrEquiv()),
1063  SelectOne, "sel.eq");
1064  } else {
1065  Value *SelectEq = Builder.CreateSelect(
1066  EmitCmp(CK_Equal), EmitCmpRes(CmpInfo.getEqualOrEquiv()),
1067  EmitCmpRes(CmpInfo.getUnordered()), "sel.eq");
1068  Value *SelectGT = Builder.CreateSelect(EmitCmp(CK_Greater),
1069  EmitCmpRes(CmpInfo.getGreater()),
1070  SelectEq, "sel.gt");
1071  Select = Builder.CreateSelect(
1072  EmitCmp(CK_Less), EmitCmpRes(CmpInfo.getLess()), SelectGT, "sel.lt");
1073  }
1074  // Create the return value in the destination slot.
1075  EnsureDest(E->getType());
1076  LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), E->getType());
1077 
1078  // Emit the address of the first (and only) field in the comparison category
1079  // type, and initialize it from the constant integer value selected above.
1081  DestLV, *CmpInfo.Record->field_begin());
1082  CGF.EmitStoreThroughLValue(RValue::get(Select), FieldLV, /*IsInit*/ true);
1083 
1084  // All done! The result is in the Dest slot.
1085 }
1086 
1087 void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) {
1088  if (E->getOpcode() == BO_PtrMemD || E->getOpcode() == BO_PtrMemI)
1089  VisitPointerToDataMemberBinaryOperator(E);
1090  else
1091  CGF.ErrorUnsupported(E, "aggregate binary expression");
1092 }
1093 
1094 void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
1095  const BinaryOperator *E) {
1097  EmitFinalDestCopy(E->getType(), LV);
1098 }
1099 
1100 /// Is the value of the given expression possibly a reference to or
1101 /// into a __block variable?
1102 static bool isBlockVarRef(const Expr *E) {
1103  // Make sure we look through parens.
1104  E = E->IgnoreParens();
1105 
1106  // Check for a direct reference to a __block variable.
1107  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
1108  const VarDecl *var = dyn_cast<VarDecl>(DRE->getDecl());
1109  return (var && var->hasAttr<BlocksAttr>());
1110  }
1111 
1112  // More complicated stuff.
1113 
1114  // Binary operators.
1115  if (const BinaryOperator *op = dyn_cast<BinaryOperator>(E)) {
1116  // For an assignment or pointer-to-member operation, just care
1117  // about the LHS.
1118  if (op->isAssignmentOp() || op->isPtrMemOp())
1119  return isBlockVarRef(op->getLHS());
1120 
1121  // For a comma, just care about the RHS.
1122  if (op->getOpcode() == BO_Comma)
1123  return isBlockVarRef(op->getRHS());
1124 
1125  // FIXME: pointer arithmetic?
1126  return false;
1127 
1128  // Check both sides of a conditional operator.
1129  } else if (const AbstractConditionalOperator *op
1130  = dyn_cast<AbstractConditionalOperator>(E)) {
1131  return isBlockVarRef(op->getTrueExpr())
1132  || isBlockVarRef(op->getFalseExpr());
1133 
1134  // OVEs are required to support BinaryConditionalOperators.
1135  } else if (const OpaqueValueExpr *op
1136  = dyn_cast<OpaqueValueExpr>(E)) {
1137  if (const Expr *src = op->getSourceExpr())
1138  return isBlockVarRef(src);
1139 
1140  // Casts are necessary to get things like (*(int*)&var) = foo().
1141  // We don't really care about the kind of cast here, except
1142  // we don't want to look through l2r casts, because it's okay
1143  // to get the *value* in a __block variable.
1144  } else if (const CastExpr *cast = dyn_cast<CastExpr>(E)) {
1145  if (cast->getCastKind() == CK_LValueToRValue)
1146  return false;
1147  return isBlockVarRef(cast->getSubExpr());
1148 
1149  // Handle unary operators. Again, just aggressively look through
1150  // it, ignoring the operation.
1151  } else if (const UnaryOperator *uop = dyn_cast<UnaryOperator>(E)) {
1152  return isBlockVarRef(uop->getSubExpr());
1153 
1154  // Look into the base of a field access.
1155  } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
1156  return isBlockVarRef(mem->getBase());
1157 
1158  // Look into the base of a subscript.
1159  } else if (const ArraySubscriptExpr *sub = dyn_cast<ArraySubscriptExpr>(E)) {
1160  return isBlockVarRef(sub->getBase());
1161  }
1162 
1163  return false;
1164 }
1165 
1166 void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1167  // For an assignment to work, the value on the right has
1168  // to be compatible with the value on the left.
1169  assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
1170  E->getRHS()->getType())
1171  && "Invalid assignment");
1172 
1173  // If the LHS might be a __block variable, and the RHS can
1174  // potentially cause a block copy, we need to evaluate the RHS first
1175  // so that the assignment goes the right place.
1176  // This is pretty semantically fragile.
1177  if (isBlockVarRef(E->getLHS()) &&
1178  E->getRHS()->HasSideEffects(CGF.getContext())) {
1179  // Ensure that we have a destination, and evaluate the RHS into that.
1180  EnsureDest(E->getRHS()->getType());
1181  Visit(E->getRHS());
1182 
1183  // Now emit the LHS and copy into it.
1185 
1186  // That copy is an atomic copy if the LHS is atomic.
1187  if (LHS.getType()->isAtomicType() ||
1189  CGF.EmitAtomicStore(Dest.asRValue(), LHS, /*isInit*/ false);
1190  return;
1191  }
1192 
1193  EmitCopy(E->getLHS()->getType(),
1195  needsGC(E->getLHS()->getType()),
1198  Dest);
1199  return;
1200  }
1201 
1202  LValue LHS = CGF.EmitLValue(E->getLHS());
1203 
1204  // If we have an atomic type, evaluate into the destination and then
1205  // do an atomic copy.
1206  if (LHS.getType()->isAtomicType() ||
1208  EnsureDest(E->getRHS()->getType());
1209  Visit(E->getRHS());
1210  CGF.EmitAtomicStore(Dest.asRValue(), LHS, /*isInit*/ false);
1211  return;
1212  }
1213 
1214  // Codegen the RHS so that it stores directly into the LHS.
1216  LHS, CGF, AggValueSlot::IsDestructed, needsGC(E->getLHS()->getType()),
1218  // A non-volatile aggregate destination might have volatile member.
1219  if (!LHSSlot.isVolatile() &&
1220  CGF.hasVolatileMember(E->getLHS()->getType()))
1221  LHSSlot.setVolatile(true);
1222 
1223  CGF.EmitAggExpr(E->getRHS(), LHSSlot);
1224 
1225  // Copy into the destination if the assignment isn't ignored.
1226  EmitFinalDestCopy(E->getType(), LHS);
1227 
1228  if (!Dest.isIgnored() && !Dest.isExternallyDestructed() &&
1231  E->getType());
1232 }
1233 
1234 void AggExprEmitter::
1235 VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
1236  llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");
1237  llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");
1238  llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end");
1239 
1240  // Bind the common expression if necessary.
1241  CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1242 
1244  CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock,
1245  CGF.getProfileCount(E));
1246 
1247  // Save whether the destination's lifetime is externally managed.
1248  bool isExternallyDestructed = Dest.isExternallyDestructed();
1249  bool destructNonTrivialCStruct =
1250  !isExternallyDestructed &&
1252  isExternallyDestructed |= destructNonTrivialCStruct;
1253  Dest.setExternallyDestructed(isExternallyDestructed);
1254 
1255  eval.begin(CGF);
1256  CGF.EmitBlock(LHSBlock);
1257  CGF.incrementProfileCounter(E);
1258  Visit(E->getTrueExpr());
1259  eval.end(CGF);
1260 
1261  assert(CGF.HaveInsertPoint() && "expression evaluation ended with no IP!");
1262  CGF.Builder.CreateBr(ContBlock);
1263 
1264  // If the result of an agg expression is unused, then the emission
1265  // of the LHS might need to create a destination slot. That's fine
1266  // with us, and we can safely emit the RHS into the same slot, but
1267  // we shouldn't claim that it's already being destructed.
1268  Dest.setExternallyDestructed(isExternallyDestructed);
1269 
1270  eval.begin(CGF);
1271  CGF.EmitBlock(RHSBlock);
1272  Visit(E->getFalseExpr());
1273  eval.end(CGF);
1274 
1275  if (destructNonTrivialCStruct)
1277  E->getType());
1278 
1279  CGF.EmitBlock(ContBlock);
1280 }
1281 
1282 void AggExprEmitter::VisitChooseExpr(const ChooseExpr *CE) {
1283  Visit(CE->getChosenSubExpr());
1284 }
1285 
1286 void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
1287  Address ArgValue = Address::invalid();
1288  Address ArgPtr = CGF.EmitVAArg(VE, ArgValue);
1289 
1290  // If EmitVAArg fails, emit an error.
1291  if (!ArgPtr.isValid()) {
1292  CGF.ErrorUnsupported(VE, "aggregate va_arg expression");
1293  return;
1294  }
1295 
1296  EmitFinalDestCopy(VE->getType(), CGF.MakeAddrLValue(ArgPtr, VE->getType()));
1297 }
1298 
1299 void AggExprEmitter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1300  // Ensure that we have a slot, but if we already do, remember
1301  // whether it was externally destructed.
1302  bool wasExternallyDestructed = Dest.isExternallyDestructed();
1303  EnsureDest(E->getType());
1304 
1305  // We're going to push a destructor if there isn't already one.
1306  Dest.setExternallyDestructed();
1307 
1308  Visit(E->getSubExpr());
1309 
1310  // Push that destructor we promised.
1311  if (!wasExternallyDestructed)
1312  CGF.EmitCXXTemporary(E->getTemporary(), E->getType(), Dest.getAddress());
1313 }
1314 
1315 void
1316 AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *E) {
1317  AggValueSlot Slot = EnsureSlot(E->getType());
1318  CGF.EmitCXXConstructExpr(E, Slot);
1319 }
1320 
1321 void AggExprEmitter::VisitCXXInheritedCtorInitExpr(
1322  const CXXInheritedCtorInitExpr *E) {
1323  AggValueSlot Slot = EnsureSlot(E->getType());
1325  E->getConstructor(), E->constructsVBase(), Slot.getAddress(),
1326  E->inheritedFromVBase(), E);
1327 }
1328 
1329 void
1330 AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) {
1331  AggValueSlot Slot = EnsureSlot(E->getType());
1332  LValue SlotLV = CGF.MakeAddrLValue(Slot.getAddress(), E->getType());
1333 
1334  // We'll need to enter cleanup scopes in case any of the element
1335  // initializers throws an exception.
1337  llvm::Instruction *CleanupDominator = nullptr;
1338 
1341  e = E->capture_init_end();
1342  i != e; ++i, ++CurField) {
1343  // Emit initialization
1344  LValue LV = CGF.EmitLValueForFieldInitialization(SlotLV, *CurField);
1345  if (CurField->hasCapturedVLAType()) {
1346  CGF.EmitLambdaVLACapture(CurField->getCapturedVLAType(), LV);
1347  continue;
1348  }
1349 
1350  EmitInitializationToLValue(*i, LV);
1351 
1352  // Push a destructor if necessary.
1353  if (QualType::DestructionKind DtorKind =
1354  CurField->getType().isDestructedType()) {
1355  assert(LV.isSimple());
1356  if (CGF.needsEHCleanup(DtorKind)) {
1357  if (!CleanupDominator)
1358  CleanupDominator = CGF.Builder.CreateAlignedLoad(
1359  CGF.Int8Ty,
1360  llvm::Constant::getNullValue(CGF.Int8PtrTy),
1361  CharUnits::One()); // placeholder
1362 
1363  CGF.pushDestroy(EHCleanup, LV.getAddress(CGF), CurField->getType(),
1364  CGF.getDestroyer(DtorKind), false);
1365  Cleanups.push_back(CGF.EHStack.stable_begin());
1366  }
1367  }
1368  }
1369 
1370  // Deactivate all the partial cleanups in reverse order, which
1371  // generally means popping them.
1372  for (unsigned i = Cleanups.size(); i != 0; --i)
1373  CGF.DeactivateCleanupBlock(Cleanups[i-1], CleanupDominator);
1374 
1375  // Destroy the placeholder if we made one.
1376  if (CleanupDominator)
1377  CleanupDominator->eraseFromParent();
1378 }
1379 
1380 void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *E) {
1381  CodeGenFunction::RunCleanupsScope cleanups(CGF);
1382  Visit(E->getSubExpr());
1383 }
1384 
1385 void AggExprEmitter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1386  QualType T = E->getType();
1387  AggValueSlot Slot = EnsureSlot(T);
1388  EmitNullInitializationToLValue(CGF.MakeAddrLValue(Slot.getAddress(), T));
1389 }
1390 
1391 void AggExprEmitter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1392  QualType T = E->getType();
1393  AggValueSlot Slot = EnsureSlot(T);
1394  EmitNullInitializationToLValue(CGF.MakeAddrLValue(Slot.getAddress(), T));
1395 }
1396 
1397 /// Determine whether the given cast kind is known to always convert values
1398 /// with all zero bits in their value representation to values with all zero
1399 /// bits in their value representation.
1400 static bool castPreservesZero(const CastExpr *CE) {
1401  switch (CE->getCastKind()) {
1402  // No-ops.
1403  case CK_NoOp:
1404  case CK_UserDefinedConversion:
1405  case CK_ConstructorConversion:
1406  case CK_BitCast:
1407  case CK_ToUnion:
1408  case CK_ToVoid:
1409  // Conversions between (possibly-complex) integral, (possibly-complex)
1410  // floating-point, and bool.
1411  case CK_BooleanToSignedIntegral:
1412  case CK_FloatingCast:
1413  case CK_FloatingComplexCast:
1414  case CK_FloatingComplexToBoolean:
1415  case CK_FloatingComplexToIntegralComplex:
1416  case CK_FloatingComplexToReal:
1417  case CK_FloatingRealToComplex:
1418  case CK_FloatingToBoolean:
1419  case CK_FloatingToIntegral:
1420  case CK_IntegralCast:
1421  case CK_IntegralComplexCast:
1422  case CK_IntegralComplexToBoolean:
1423  case CK_IntegralComplexToFloatingComplex:
1424  case CK_IntegralComplexToReal:
1425  case CK_IntegralRealToComplex:
1426  case CK_IntegralToBoolean:
1427  case CK_IntegralToFloating:
1428  // Reinterpreting integers as pointers and vice versa.
1429  case CK_IntegralToPointer:
1430  case CK_PointerToIntegral:
1431  // Language extensions.
1432  case CK_VectorSplat:
1433  case CK_MatrixCast:
1434  case CK_NonAtomicToAtomic:
1435  case CK_AtomicToNonAtomic:
1436  return true;
1437 
1438  case CK_BaseToDerivedMemberPointer:
1439  case CK_DerivedToBaseMemberPointer:
1440  case CK_MemberPointerToBoolean:
1441  case CK_NullToMemberPointer:
1442  case CK_ReinterpretMemberPointer:
1443  // FIXME: ABI-dependent.
1444  return false;
1445 
1446  case CK_AnyPointerToBlockPointerCast:
1447  case CK_BlockPointerToObjCPointerCast:
1448  case CK_CPointerToObjCPointerCast:
1449  case CK_ObjCObjectLValueCast:
1450  case CK_IntToOCLSampler:
1451  case CK_ZeroToOCLOpaqueType:
1452  // FIXME: Check these.
1453  return false;
1454 
1455  case CK_FixedPointCast:
1456  case CK_FixedPointToBoolean:
1457  case CK_FixedPointToFloating:
1458  case CK_FixedPointToIntegral:
1459  case CK_FloatingToFixedPoint:
1460  case CK_IntegralToFixedPoint:
1461  // FIXME: Do all fixed-point types represent zero as all 0 bits?
1462  return false;
1463 
1464  case CK_AddressSpaceConversion:
1465  case CK_BaseToDerived:
1466  case CK_DerivedToBase:
1467  case CK_Dynamic:
1468  case CK_NullToPointer:
1469  case CK_PointerToBoolean:
1470  // FIXME: Preserves zeroes only if zero pointers and null pointers have the
1471  // same representation in all involved address spaces.
1472  return false;
1473 
1474  case CK_ARCConsumeObject:
1475  case CK_ARCExtendBlockObject:
1476  case CK_ARCProduceObject:
1477  case CK_ARCReclaimReturnedObject:
1478  case CK_CopyAndAutoreleaseBlockObject:
1479  case CK_ArrayToPointerDecay:
1480  case CK_FunctionToPointerDecay:
1481  case CK_BuiltinFnToFnPtr:
1482  case CK_Dependent:
1483  case CK_LValueBitCast:
1484  case CK_LValueToRValue:
1485  case CK_LValueToRValueBitCast:
1486  case CK_UncheckedDerivedToBase:
1487  return false;
1488  }
1489  llvm_unreachable("Unhandled clang::CastKind enum");
1490 }
1491 
1492 /// isSimpleZero - If emitting this value will obviously just cause a store of
1493 /// zero to memory, return true. This can return false if uncertain, so it just
1494 /// handles simple cases.
1495 static bool isSimpleZero(const Expr *E, CodeGenFunction &CGF) {
1496  E = E->IgnoreParens();
1497  while (auto *CE = dyn_cast<CastExpr>(E)) {
1498  if (!castPreservesZero(CE))
1499  break;
1500  E = CE->getSubExpr()->IgnoreParens();
1501  }
1502 
1503  // 0
1504  if (const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(E))
1505  return IL->getValue() == 0;
1506  // +0.0
1507  if (const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(E))
1508  return FL->getValue().isPosZero();
1509  // int()
1510  if ((isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) &&
1511  CGF.getTypes().isZeroInitializable(E->getType()))
1512  return true;
1513  // (int*)0 - Null pointer expressions.
1514  if (const CastExpr *ICE = dyn_cast<CastExpr>(E))
1515  return ICE->getCastKind() == CK_NullToPointer &&
1517  !E->HasSideEffects(CGF.getContext());
1518  // '\0'
1519  if (const CharacterLiteral *CL = dyn_cast<CharacterLiteral>(E))
1520  return CL->getValue() == 0;
1521 
1522  // Otherwise, hard case: conservatively return false.
1523  return false;
1524 }
1525 
1526 
1527 void
1528 AggExprEmitter::EmitInitializationToLValue(Expr *E, LValue LV) {
1529  QualType type = LV.getType();
1530  // FIXME: Ignore result?
1531  // FIXME: Are initializers affected by volatile?
1532  if (Dest.isZeroed() && isSimpleZero(E, CGF)) {
1533  // Storing "i32 0" to a zero'd memory location is a noop.
1534  return;
1535  } else if (isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) {
1536  return EmitNullInitializationToLValue(LV);
1537  } else if (isa<NoInitExpr>(E)) {
1538  // Do nothing.
1539  return;
1540  } else if (type->isReferenceType()) {
1541  RValue RV = CGF.EmitReferenceBindingToExpr(E);
1542  return CGF.EmitStoreThroughLValue(RV, LV);
1543  }
1544 
1545  switch (CGF.getEvaluationKind(type)) {
1546  case TEK_Complex:
1547  CGF.EmitComplexExprIntoLValue(E, LV, /*isInit*/ true);
1548  return;
1549  case TEK_Aggregate:
1550  CGF.EmitAggExpr(
1555  return;
1556  case TEK_Scalar:
1557  if (LV.isSimple()) {
1558  CGF.EmitScalarInit(E, /*D=*/nullptr, LV, /*Captured=*/false);
1559  } else {
1561  }
1562  return;
1563  }
1564  llvm_unreachable("bad evaluation kind");
1565 }
1566 
1567 void AggExprEmitter::EmitNullInitializationToLValue(LValue lv) {
1568  QualType type = lv.getType();
1569 
1570  // If the destination slot is already zeroed out before the aggregate is
1571  // copied into it, we don't have to emit any zeros here.
1572  if (Dest.isZeroed() && CGF.getTypes().isZeroInitializable(type))
1573  return;
1574 
1575  if (CGF.hasScalarEvaluationKind(type)) {
1576  // For non-aggregates, we can store the appropriate null constant.
1577  llvm::Value *null = CGF.CGM.EmitNullConstant(type);
1578  // Note that the following is not equivalent to
1579  // EmitStoreThroughBitfieldLValue for ARC types.
1580  if (lv.isBitField()) {
1582  } else {
1583  assert(lv.isSimple());
1584  CGF.EmitStoreOfScalar(null, lv, /* isInitialization */ true);
1585  }
1586  } else {
1587  // There's a potential optimization opportunity in combining
1588  // memsets; that would be easy for arrays, but relatively
1589  // difficult for structures with the current code.
1590  CGF.EmitNullInitialization(lv.getAddress(CGF), lv.getType());
1591  }
1592 }
1593 
1594 void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
1595 #if 0
1596  // FIXME: Assess perf here? Figure out what cases are worth optimizing here
1597  // (Length of globals? Chunks of zeroed-out space?).
1598  //
1599  // If we can, prefer a copy from a global; this is a lot less code for long
1600  // globals, and it's easier for the current optimizers to analyze.
1601  if (llvm::Constant* C = CGF.CGM.EmitConstantExpr(E, E->getType(), &CGF)) {
1602  llvm::GlobalVariable* GV =
1603  new llvm::GlobalVariable(CGF.CGM.getModule(), C->getType(), true,
1605  EmitFinalDestCopy(E->getType(), CGF.MakeAddrLValue(GV, E->getType()));
1606  return;
1607  }
1608 #endif
1609  if (E->hadArrayRangeDesignator())
1610  CGF.ErrorUnsupported(E, "GNU array range designator extension");
1611 
1612  if (E->isTransparent())
1613  return Visit(E->getInit(0));
1614 
1615  AggValueSlot Dest = EnsureSlot(E->getType());
1616 
1617  LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), E->getType());
1618 
1619  // Handle initialization of an array.
1620  if (E->getType()->isArrayType()) {
1621  auto AType = cast<llvm::ArrayType>(Dest.getAddress().getElementType());
1622  EmitArrayInit(Dest.getAddress(), AType, E->getType(), E);
1623  return;
1624  }
1625 
1626  assert(E->getType()->isRecordType() && "Only support structs/unions here!");
1627 
1628  // Do struct initialization; this code just sets each individual member
1629  // to the approprate value. This makes bitfield support automatic;
1630  // the disadvantage is that the generated code is more difficult for
1631  // the optimizer, especially with bitfields.
1632  unsigned NumInitElements = E->getNumInits();
1633  RecordDecl *record = E->getType()->castAs<RecordType>()->getDecl();
1634 
1635  // We'll need to enter cleanup scopes in case any of the element
1636  // initializers throws an exception.
1638  llvm::Instruction *cleanupDominator = nullptr;
1639  auto addCleanup = [&](const EHScopeStack::stable_iterator &cleanup) {
1640  cleanups.push_back(cleanup);
1641  if (!cleanupDominator) // create placeholder once needed
1642  cleanupDominator = CGF.Builder.CreateAlignedLoad(
1643  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
1644  CharUnits::One());
1645  };
1646 
1647  unsigned curInitIndex = 0;
1648 
1649  // Emit initialization of base classes.
1650  if (auto *CXXRD = dyn_cast<CXXRecordDecl>(record)) {
1651  assert(E->getNumInits() >= CXXRD->getNumBases() &&
1652  "missing initializer for base class");
1653  for (auto &Base : CXXRD->bases()) {
1654  assert(!Base.isVirtual() && "should not see vbases here");
1655  auto *BaseRD = Base.getType()->getAsCXXRecordDecl();
1657  Dest.getAddress(), CXXRD, BaseRD,
1658  /*isBaseVirtual*/ false);
1660  V, Qualifiers(),
1664  CGF.getOverlapForBaseInit(CXXRD, BaseRD, Base.isVirtual()));
1665  CGF.EmitAggExpr(E->getInit(curInitIndex++), AggSlot);
1666 
1667  if (QualType::DestructionKind dtorKind =
1668  Base.getType().isDestructedType()) {
1669  CGF.pushDestroy(dtorKind, V, Base.getType());
1670  addCleanup(CGF.EHStack.stable_begin());
1671  }
1672  }
1673  }
1674 
1675  // Prepare a 'this' for CXXDefaultInitExprs.
1677 
1678  if (record->isUnion()) {
1679  // Only initialize one field of a union. The field itself is
1680  // specified by the initializer list.
1681  if (!E->getInitializedFieldInUnion()) {
1682  // Empty union; we have nothing to do.
1683 
1684 #ifndef NDEBUG
1685  // Make sure that it's really an empty and not a failure of
1686  // semantic analysis.
1687  for (const auto *Field : record->fields())
1688  assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
1689 #endif
1690  return;
1691  }
1692 
1693  // FIXME: volatility
1695 
1696  LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestLV, Field);
1697  if (NumInitElements) {
1698  // Store the initializer into the field
1699  EmitInitializationToLValue(E->getInit(0), FieldLoc);
1700  } else {
1701  // Default-initialize to null.
1702  EmitNullInitializationToLValue(FieldLoc);
1703  }
1704 
1705  return;
1706  }
1707 
1708  // Here we iterate over the fields; this makes it simpler to both
1709  // default-initialize fields and skip over unnamed fields.
1710  for (const auto *field : record->fields()) {
1711  // We're done once we hit the flexible array member.
1712  if (field->getType()->isIncompleteArrayType())
1713  break;
1714 
1715  // Always skip anonymous bitfields.
1716  if (field->isUnnamedBitfield())
1717  continue;
1718 
1719  // We're done if we reach the end of the explicit initializers, we
1720  // have a zeroed object, and the rest of the fields are
1721  // zero-initializable.
1722  if (curInitIndex == NumInitElements && Dest.isZeroed() &&
1723  CGF.getTypes().isZeroInitializable(E->getType()))
1724  break;
1725 
1726 
1727  LValue LV = CGF.EmitLValueForFieldInitialization(DestLV, field);
1728  // We never generate write-barries for initialized fields.
1729  LV.setNonGC(true);
1730 
1731  if (curInitIndex < NumInitElements) {
1732  // Store the initializer into the field.
1733  EmitInitializationToLValue(E->getInit(curInitIndex++), LV);
1734  } else {
1735  // We're out of initializers; default-initialize to null
1736  EmitNullInitializationToLValue(LV);
1737  }
1738 
1739  // Push a destructor if necessary.
1740  // FIXME: if we have an array of structures, all explicitly
1741  // initialized, we can end up pushing a linear number of cleanups.
1742  bool pushedCleanup = false;
1743  if (QualType::DestructionKind dtorKind
1744  = field->getType().isDestructedType()) {
1745  assert(LV.isSimple());
1746  if (CGF.needsEHCleanup(dtorKind)) {
1747  CGF.pushDestroy(EHCleanup, LV.getAddress(CGF), field->getType(),
1748  CGF.getDestroyer(dtorKind), false);
1749  addCleanup(CGF.EHStack.stable_begin());
1750  pushedCleanup = true;
1751  }
1752  }
1753 
1754  // If the GEP didn't get used because of a dead zero init or something
1755  // else, clean it up for -O0 builds and general tidiness.
1756  if (!pushedCleanup && LV.isSimple())
1757  if (llvm::GetElementPtrInst *GEP =
1758  dyn_cast<llvm::GetElementPtrInst>(LV.getPointer(CGF)))
1759  if (GEP->use_empty())
1760  GEP->eraseFromParent();
1761  }
1762 
1763  // Deactivate all the partial cleanups in reverse order, which
1764  // generally means popping them.
1765  assert((cleanupDominator || cleanups.empty()) &&
1766  "Missing cleanupDominator before deactivating cleanup blocks");
1767  for (unsigned i = cleanups.size(); i != 0; --i)
1768  CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
1769 
1770  // Destroy the placeholder if we made one.
1771  if (cleanupDominator)
1772  cleanupDominator->eraseFromParent();
1773 }
1774 
1775 void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
1776  llvm::Value *outerBegin) {
1777  // Emit the common subexpression.
1779 
1780  Address destPtr = EnsureSlot(E->getType()).getAddress();
1781  uint64_t numElements = E->getArraySize().getZExtValue();
1782 
1783  if (!numElements)
1784  return;
1785 
1786  // destPtr is an array*. Construct an elementType* by drilling down a level.
1787  llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
1788  llvm::Value *indices[] = {zero, zero};
1789  llvm::Value *begin = Builder.CreateInBoundsGEP(
1790  destPtr.getElementType(), destPtr.getPointer(), indices,
1791  "arrayinit.begin");
1792 
1793  // Prepare to special-case multidimensional array initialization: we avoid
1794  // emitting multiple destructor loops in that case.
1795  if (!outerBegin)
1796  outerBegin = begin;
1797  ArrayInitLoopExpr *InnerLoop = dyn_cast<ArrayInitLoopExpr>(E->getSubExpr());
1798 
1799  QualType elementType =
1801  CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
1802  CharUnits elementAlign =
1803  destPtr.getAlignment().alignmentOfArrayElement(elementSize);
1804  llvm::Type *llvmElementType = CGF.ConvertTypeForMem(elementType);
1805 
1806  llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
1807  llvm::BasicBlock *bodyBB = CGF.createBasicBlock("arrayinit.body");
1808 
1809  // Jump into the body.
1810  CGF.EmitBlock(bodyBB);
1811  llvm::PHINode *index =
1812  Builder.CreatePHI(zero->getType(), 2, "arrayinit.index");
1813  index->addIncoming(zero, entryBB);
1814  llvm::Value *element =
1815  Builder.CreateInBoundsGEP(llvmElementType, begin, index);
1816 
1817  // Prepare for a cleanup.
1818  QualType::DestructionKind dtorKind = elementType.isDestructedType();
1820  if (CGF.needsEHCleanup(dtorKind) && !InnerLoop) {
1821  if (outerBegin->getType() != element->getType())
1822  outerBegin = Builder.CreateBitCast(outerBegin, element->getType());
1823  CGF.pushRegularPartialArrayCleanup(outerBegin, element, elementType,
1824  elementAlign,
1825  CGF.getDestroyer(dtorKind));
1826  cleanup = CGF.EHStack.stable_begin();
1827  } else {
1828  dtorKind = QualType::DK_none;
1829  }
1830 
1831  // Emit the actual filler expression.
1832  {
1833  // Temporaries created in an array initialization loop are destroyed
1834  // at the end of each iteration.
1835  CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
1837  LValue elementLV = CGF.MakeAddrLValue(
1838  Address(element, llvmElementType, elementAlign), elementType);
1839 
1840  if (InnerLoop) {
1841  // If the subexpression is an ArrayInitLoopExpr, share its cleanup.
1842  auto elementSlot = AggValueSlot::forLValue(
1843  elementLV, CGF, AggValueSlot::IsDestructed,
1846  AggExprEmitter(CGF, elementSlot, false)
1847  .VisitArrayInitLoopExpr(InnerLoop, outerBegin);
1848  } else
1849  EmitInitializationToLValue(E->getSubExpr(), elementLV);
1850  }
1851 
1852  // Move on to the next element.
1853  llvm::Value *nextIndex = Builder.CreateNUWAdd(
1854  index, llvm::ConstantInt::get(CGF.SizeTy, 1), "arrayinit.next");
1855  index->addIncoming(nextIndex, Builder.GetInsertBlock());
1856 
1857  // Leave the loop if we're done.
1858  llvm::Value *done = Builder.CreateICmpEQ(
1859  nextIndex, llvm::ConstantInt::get(CGF.SizeTy, numElements),
1860  "arrayinit.done");
1861  llvm::BasicBlock *endBB = CGF.createBasicBlock("arrayinit.end");
1862  Builder.CreateCondBr(done, endBB, bodyBB);
1863 
1864  CGF.EmitBlock(endBB);
1865 
1866  // Leave the partial-array cleanup if we entered one.
1867  if (dtorKind)
1868  CGF.DeactivateCleanupBlock(cleanup, index);
1869 }
1870 
1871 void AggExprEmitter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1872  AggValueSlot Dest = EnsureSlot(E->getType());
1873 
1874  LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), E->getType());
1875  EmitInitializationToLValue(E->getBase(), DestLV);
1876  VisitInitListExpr(E->getUpdater());
1877 }
1878 
1879 //===----------------------------------------------------------------------===//
1880 // Entry Points into this File
1881 //===----------------------------------------------------------------------===//
1882 
1883 /// GetNumNonZeroBytesInInit - Get an approximate count of the number of
1884 /// non-zero bytes that will be stored when outputting the initializer for the
1885 /// specified initializer expression.
1887  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
1888  E = MTE->getSubExpr();
1889  E = E->IgnoreParenNoopCasts(CGF.getContext());
1890 
1891  // 0 and 0.0 won't require any non-zero stores!
1892  if (isSimpleZero(E, CGF)) return CharUnits::Zero();
1893 
1894  // If this is an initlist expr, sum up the size of sizes of the (present)
1895  // elements. If this is something weird, assume the whole thing is non-zero.
1896  const InitListExpr *ILE = dyn_cast<InitListExpr>(E);
1897  while (ILE && ILE->isTransparent())
1898  ILE = dyn_cast<InitListExpr>(ILE->getInit(0));
1899  if (!ILE || !CGF.getTypes().isZeroInitializable(ILE->getType()))
1900  return CGF.getContext().getTypeSizeInChars(E->getType());
1901 
1902  // InitListExprs for structs have to be handled carefully. If there are
1903  // reference members, we need to consider the size of the reference, not the
1904  // referencee. InitListExprs for unions and arrays can't have references.
1905  if (const RecordType *RT = E->getType()->getAs<RecordType>()) {
1906  if (!RT->isUnionType()) {
1907  RecordDecl *SD = RT->getDecl();
1908  CharUnits NumNonZeroBytes = CharUnits::Zero();
1909 
1910  unsigned ILEElement = 0;
1911  if (auto *CXXRD = dyn_cast<CXXRecordDecl>(SD))
1912  while (ILEElement != CXXRD->getNumBases())
1913  NumNonZeroBytes +=
1914  GetNumNonZeroBytesInInit(ILE->getInit(ILEElement++), CGF);
1915  for (const auto *Field : SD->fields()) {
1916  // We're done once we hit the flexible array member or run out of
1917  // InitListExpr elements.
1918  if (Field->getType()->isIncompleteArrayType() ||
1919  ILEElement == ILE->getNumInits())
1920  break;
1921  if (Field->isUnnamedBitfield())
1922  continue;
1923 
1924  const Expr *E = ILE->getInit(ILEElement++);
1925 
1926  // Reference values are always non-null and have the width of a pointer.
1927  if (Field->getType()->isReferenceType())
1928  NumNonZeroBytes += CGF.getContext().toCharUnitsFromBits(
1930  else
1931  NumNonZeroBytes += GetNumNonZeroBytesInInit(E, CGF);
1932  }
1933 
1934  return NumNonZeroBytes;
1935  }
1936  }
1937 
1938  // FIXME: This overestimates the number of non-zero bytes for bit-fields.
1939  CharUnits NumNonZeroBytes = CharUnits::Zero();
1940  for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
1941  NumNonZeroBytes += GetNumNonZeroBytesInInit(ILE->getInit(i), CGF);
1942  return NumNonZeroBytes;
1943 }
1944 
1945 /// CheckAggExprForMemSetUse - If the initializer is large and has a lot of
1946 /// zeros in it, emit a memset and avoid storing the individual zeros.
1947 ///
1948 static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E,
1949  CodeGenFunction &CGF) {
1950  // If the slot is already known to be zeroed, nothing to do. Don't mess with
1951  // volatile stores.
1952  if (Slot.isZeroed() || Slot.isVolatile() || !Slot.getAddress().isValid())
1953  return;
1954 
1955  // C++ objects with a user-declared constructor don't need zero'ing.
1956  if (CGF.getLangOpts().CPlusPlus)
1957  if (const RecordType *RT = CGF.getContext()
1959  const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
1960  if (RD->hasUserDeclaredConstructor())
1961  return;
1962  }
1963 
1964  // If the type is 16-bytes or smaller, prefer individual stores over memset.
1965  CharUnits Size = Slot.getPreferredSize(CGF.getContext(), E->getType());
1966  if (Size <= CharUnits::fromQuantity(16))
1967  return;
1968 
1969  // Check to see if over 3/4 of the initializer are known to be zero. If so,
1970  // we prefer to emit memset + individual stores for the rest.
1971  CharUnits NumNonZeroBytes = GetNumNonZeroBytesInInit(E, CGF);
1972  if (NumNonZeroBytes*4 > Size)
1973  return;
1974 
1975  // Okay, it seems like a good idea to use an initial memset, emit the call.
1976  llvm::Constant *SizeVal = CGF.Builder.getInt64(Size.getQuantity());
1977 
1978  Address Loc = Slot.getAddress();
1979  Loc = CGF.Builder.CreateElementBitCast(Loc, CGF.Int8Ty);
1980  CGF.Builder.CreateMemSet(Loc, CGF.Builder.getInt8(0), SizeVal, false);
1981 
1982  // Tell the AggExprEmitter that the slot is known zero.
1983  Slot.setZeroed();
1984 }
1985 
1986 
1987 
1988 
1989 /// EmitAggExpr - Emit the computation of the specified expression of aggregate
1990 /// type. The result is computed into DestPtr. Note that if DestPtr is null,
1991 /// the value of the aggregate expression is not needed. If VolatileDest is
1992 /// true, DestPtr cannot be 0.
1994  assert(E && hasAggregateEvaluationKind(E->getType()) &&
1995  "Invalid aggregate expression to emit");
1996  assert((Slot.getAddress().isValid() || Slot.isIgnored()) &&
1997  "slot has bits but no address");
1998 
1999  // Optimize the slot if possible.
2000  CheckAggExprForMemSetUse(Slot, E, *this);
2001 
2002  AggExprEmitter(*this, Slot, Slot.isIgnored()).Visit(const_cast<Expr*>(E));
2003 }
2004 
2006  assert(hasAggregateEvaluationKind(E->getType()) && "Invalid argument!");
2007  Address Temp = CreateMemTemp(E->getType());
2008  LValue LV = MakeAddrLValue(Temp, E->getType());
2010  LV, *this, AggValueSlot::IsNotDestructed,
2013  return LV;
2014 }
2015 
2018  if (!FD->hasAttr<NoUniqueAddressAttr>() || !FD->getType()->isRecordType())
2020 
2021  // If the field lies entirely within the enclosing class's nvsize, its tail
2022  // padding cannot overlap any already-initialized object. (The only subobjects
2023  // with greater addresses that might already be initialized are vbases.)
2024  const RecordDecl *ClassRD = FD->getParent();
2025  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(ClassRD);
2026  if (Layout.getFieldOffset(FD->getFieldIndex()) +
2027  getContext().getTypeSize(FD->getType()) <=
2028  (uint64_t)getContext().toBits(Layout.getNonVirtualSize()))
2030 
2031  // The tail padding may contain values we need to preserve.
2032  return AggValueSlot::MayOverlap;
2033 }
2034 
2036  const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual) {
2037  // If the most-derived object is a field declared with [[no_unique_address]],
2038  // the tail padding of any virtual base could be reused for other subobjects
2039  // of that field's class.
2040  if (IsVirtual)
2041  return AggValueSlot::MayOverlap;
2042 
2043  // If the base class is laid out entirely within the nvsize of the derived
2044  // class, its tail padding cannot yet be initialized, so we can issue
2045  // stores at the full width of the base class.
2046  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
2047  if (Layout.getBaseClassOffset(BaseRD) +
2048  getContext().getASTRecordLayout(BaseRD).getSize() <=
2049  Layout.getNonVirtualSize())
2051 
2052  // The tail padding may contain values we need to preserve.
2053  return AggValueSlot::MayOverlap;
2054 }
2055 
2057  AggValueSlot::Overlap_t MayOverlap,
2058  bool isVolatile) {
2059  assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex");
2060 
2061  Address DestPtr = Dest.getAddress(*this);
2062  Address SrcPtr = Src.getAddress(*this);
2063 
2064  if (getLangOpts().CPlusPlus) {
2065  if (const RecordType *RT = Ty->getAs<RecordType>()) {
2066  CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl());
2067  assert((Record->hasTrivialCopyConstructor() ||
2068  Record->hasTrivialCopyAssignment() ||
2069  Record->hasTrivialMoveConstructor() ||
2070  Record->hasTrivialMoveAssignment() ||
2071  Record->hasAttr<TrivialABIAttr>() || Record->isUnion()) &&
2072  "Trying to aggregate-copy a type without a trivial copy/move "
2073  "constructor or assignment operator");
2074  // Ignore empty classes in C++.
2075  if (Record->isEmpty())
2076  return;
2077  }
2078  }
2079 
2080  if (getLangOpts().CUDAIsDevice) {
2081  if (Ty->isCUDADeviceBuiltinSurfaceType()) {
2082  if (getTargetHooks().emitCUDADeviceBuiltinSurfaceDeviceCopy(*this, Dest,
2083  Src))
2084  return;
2085  } else if (Ty->isCUDADeviceBuiltinTextureType()) {
2086  if (getTargetHooks().emitCUDADeviceBuiltinTextureDeviceCopy(*this, Dest,
2087  Src))
2088  return;
2089  }
2090  }
2091 
2092  // Aggregate assignment turns into llvm.memcpy. This is almost valid per
2093  // C99 6.5.16.1p3, which states "If the value being stored in an object is
2094  // read from another object that overlaps in anyway the storage of the first
2095  // object, then the overlap shall be exact and the two objects shall have
2096  // qualified or unqualified versions of a compatible type."
2097  //
2098  // memcpy is not defined if the source and destination pointers are exactly
2099  // equal, but other compilers do this optimization, and almost every memcpy
2100  // implementation handles this case safely. If there is a libc that does not
2101  // safely handle this, we can add a target hook.
2102 
2103  // Get data size info for this aggregate. Don't copy the tail padding if this
2104  // might be a potentially-overlapping subobject, since the tail padding might
2105  // be occupied by a different object. Otherwise, copying it is fine.
2107  if (MayOverlap)
2109  else
2111 
2112  llvm::Value *SizeVal = nullptr;
2113  if (TypeInfo.Width.isZero()) {
2114  // But note that getTypeInfo returns 0 for a VLA.
2115  if (auto *VAT = dyn_cast_or_null<VariableArrayType>(
2116  getContext().getAsArrayType(Ty))) {
2117  QualType BaseEltTy;
2118  SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr);
2119  TypeInfo = getContext().getTypeInfoInChars(BaseEltTy);
2120  assert(!TypeInfo.Width.isZero());
2121  SizeVal = Builder.CreateNUWMul(
2122  SizeVal,
2123  llvm::ConstantInt::get(SizeTy, TypeInfo.Width.getQuantity()));
2124  }
2125  }
2126  if (!SizeVal) {
2127  SizeVal = llvm::ConstantInt::get(SizeTy, TypeInfo.Width.getQuantity());
2128  }
2129 
2130  // FIXME: If we have a volatile struct, the optimizer can remove what might
2131  // appear to be `extra' memory ops:
2132  //
2133  // volatile struct { int i; } a, b;
2134  //
2135  // int main() {
2136  // a = b;
2137  // a = b;
2138  // }
2139  //
2140  // we need to use a different call here. We use isVolatile to indicate when
2141  // either the source or the destination is volatile.
2142 
2143  DestPtr = Builder.CreateElementBitCast(DestPtr, Int8Ty);
2144  SrcPtr = Builder.CreateElementBitCast(SrcPtr, Int8Ty);
2145 
2146  // Don't do any of the memmove_collectable tests if GC isn't set.
2147  if (CGM.getLangOpts().getGC() == LangOptions::NonGC) {
2148  // fall through
2149  } else if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
2150  RecordDecl *Record = RecordTy->getDecl();
2151  if (Record->hasObjectMember()) {
2152  CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, DestPtr, SrcPtr,
2153  SizeVal);
2154  return;
2155  }
2156  } else if (Ty->isArrayType()) {
2157  QualType BaseType = getContext().getBaseElementType(Ty);
2158  if (const RecordType *RecordTy = BaseType->getAs<RecordType>()) {
2159  if (RecordTy->getDecl()->hasObjectMember()) {
2160  CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, DestPtr, SrcPtr,
2161  SizeVal);
2162  return;
2163  }
2164  }
2165  }
2166 
2167  auto Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2168 
2169  // Determine the metadata to describe the position of any padding in this
2170  // memcpy, as well as the TBAA tags for the members of the struct, in case
2171  // the optimizer wishes to expand it in to scalar memory operations.
2172  if (llvm::MDNode *TBAAStructTag = CGM.getTBAAStructInfo(Ty))
2173  Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
2174 
2175  if (CGM.getCodeGenOpts().NewStructPathTBAA) {
2177  Dest.getTBAAInfo(), Src.getTBAAInfo());
2178  CGM.DecorateInstructionWithTBAA(Inst, TBAAInfo);
2179  }
2180 }
clang::StmtVisitor
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:183
clang::QualType::PCK_Struct
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1259
clang::CodeGen::CodeGenModule::isTypeConstant
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
Definition: CodeGenModule.cpp:4250
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:210
clang::ASTContext::getTypeSizeInChars
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Definition: ASTContext.cpp:2515
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4269
clang::CodeGen::CodeGenFunction::EmitComplexExprIntoLValue
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Definition: CGExprComplex.cpp:1300
clang::CodeGen::CodeGenFunction::callCStructCopyConstructor
void callCStructCopyConstructor(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:886
clang::CodeGen::CGBuilderTy::CreateMemCpy
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:312
clang::AtomicExpr
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6239
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6973
clang::QualType::DK_nontrivial_c_struct
@ DK_nontrivial_c_struct
Definition: Type.h:1280
clang::CodeGen::CodeGenTypeCache::SizeTy
llvm::IntegerType * SizeTy
Definition: CodeGenTypeCache.h:50
clang::CodeGen::CodeGenFunction::getTypeSize
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
Definition: CGStmtOpenMP.cpp:305
clang::CodeGen::CodeGenFunction::getProfileCount
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
Definition: CodeGenFunction.h:1537
clang::RecordDecl::field_begin
field_iterator field_begin() const
Definition: Decl.cpp:4754
clang::CodeGen::CodeGenFunction::EmitStoreThroughBitfieldLValue
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
Definition: CGExpr.cpp:2208
clang::ASTRecordLayout::getFieldOffset
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
clang::CodeGen::CodeGenFunction::EmitNullInitialization
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Definition: CodeGenFunction.cpp:1967
clang::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
clang::CXXRecordDecl::isTriviallyCopyable
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
Definition: DeclCXX.cpp:574
clang::CodeGen::CodeGenModule::EmitNullConstant
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
Definition: CGExprConstant.cpp:2342
clang::CharUnits::alignmentOfArrayElement
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition: CharUnits.h:207
clang::DeclContext::specific_decl_iterator
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2198
clang::CodeGen::TEK_Aggregate
@ TEK_Aggregate
Definition: CodeGenFunction.h:109
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
clang::CodeGen::AggValueSlot::requiresGCollection
NeedsGCBarriers_t requiresGCollection() const
Definition: CGValue.h:619
clang::CodeGen::AggValueSlot::getPointer
llvm::Value * getPointer() const
Definition: CGValue.h:623
clang::CodeGen::RValue::getAggregate
static RValue getAggregate(Address addr, bool isVolatile=false)
Definition: CGValue.h:110
clang::CodeGen::CodeGenFunction::EmitAggregateStore
void EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile)
Build all the stores needed to initialize an aggregate at Dest with the value Val.
Definition: CGCall.cpp:1332
castPreservesZero
static bool castPreservesZero(const CastExpr *CE)
Determine whether the given cast kind is known to always convert values with all zero bits in their v...
Definition: CGExprAgg.cpp:1400
clang::CodeGen::CodeGenFunction::EmitReferenceBindingToExpr
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
Definition: CGExpr.cpp:615
clang::CXXDefaultArgExpr::getExpr
const Expr * getExpr() const
Definition: ExprCXX.h:1287
CodeGenFunction.h
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::CodeGen::CGObjCRuntime::EmitGCMemmoveCollectable
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, llvm::Value *Size)=0
clang::ConstantArrayType
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3058
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::DesignatedInitUpdateExpr::getBase
Expr * getBase() const
Definition: Expr.h:5391
clang::CodeGen::CodeGenFunction::EmitLifetimeEnd
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
Definition: CGDecl.cpp:1351
clang::CodeGen::CodeGenFunction::EmitCoyieldExpr
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Definition: CGCoroutine.cpp:268
llvm::SmallVector
Definition: LLVM.h:38
clang::MaterializeTemporaryExpr::getSubExpr
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition: ExprCXX.h:4530
clang::AbstractConditionalOperator
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4112
clang::CodeGen::CodeGenFunction::EmitPseudoObjectRValue
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
Definition: CGExpr.cpp:5630
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:341
clang::CodeGen::CodeGenFunction::CXXDefaultArgExprScope
Definition: CodeGenFunction.h:1641
clang::RecordDecl::field_iterator
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:4206
clang::CodeGen::CodeGenFunction::EmitAtomicStore
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Definition: CGAtomic.cpp:2028
isBlockVarRef
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
Definition: CGExprAgg.cpp:1102
clang::CodeGen::CodeGenFunction::emitArrayLength
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
Definition: CodeGenFunction.cpp:2068
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3530
clang::NoInitExpr
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:5335
clang::CXXRewrittenBinaryOperator::getSemanticForm
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:302
clang::CXXBindTemporaryExpr::getSubExpr
const Expr * getSubExpr() const
Definition: ExprCXX.h:1441
clang::CodeGen::CodeGenFunction::EmitAnyExpr
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
Definition: CGExpr.cpp:212
clang::CodeGen::CodeGenTypeCache::getPointerAlign
CharUnits getPointerAlign() const
Definition: CodeGenTypeCache.h:117
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
Attr.h
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:56
clang::ASTRecordLayout::getBaseClassOffset
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:249
clang::AbstractConditionalOperator::getTrueExpr
Expr * getTrueExpr() const
Definition: Expr.h:4296
isTrivialFiller
static bool isTrivialFiller(Expr *E)
Determine if E is a trivial array filler, that is, one that is equivalent to zero-initialization.
Definition: CGExprAgg.cpp:453
clang::cast
U cast(CodeGen::Address addr)
Definition: Address.h:174
clang::CXXTypeidExpr
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:846
clang::ComparisonCategories::getInfoForType
const ComparisonCategoryInfo & getInfoForType(QualType Ty) const
Return the comparison category information as specified by getCategoryForType(Ty).
Definition: ComparisonCategories.cpp:160
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:722
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:91
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6984
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:773
clang::CXXInheritedCtorInitExpr::getConstructor
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1693
clang::ArrayInitLoopExpr::getArraySize
llvm::APInt getArraySize() const
Definition: Expr.h:5448
clang::CodeGen::CodeGenFunction::EmitCoawaitExpr
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Definition: CGCoroutine.cpp:261
DeclCXX.h
clang::TypeInfo::Width
uint64_t Width
Definition: ASTContext.h:180
clang::CodeGen::CodeGenFunction::createBasicBlock
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Definition: CodeGenFunction.h:2428
clang::CodeGen::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:2378
clang::Type::isRealFloatingType
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2138
clang::Expr::IgnoreParenNoopCasts
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parenthese and casts which do not change the value (including ptr->int casts of the sam...
Definition: Expr.cpp:3062
clang::CodeGen::CodeGenFunction::OpaqueValueMapping
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Definition: CodeGenFunction.h:1330
clang::CodeGen::AggValueSlot::mayOverlap
Overlap_t mayOverlap() const
Definition: CGValue.h:643
clang::StmtExpr::getSubStmt
CompoundStmt * getSubStmt()
Definition: Expr.h:4371
CGObjCRuntime.h
clang::InitListExpr
Describes an C or C++ initializer list.
Definition: Expr.h:4796
TargetInfo.h
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2172
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:723
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6705
clang::CXXRecordDecl::hasUserDeclaredConstructor
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Definition: DeclCXX.h:769
clang::CodeGen::CodeGenFunction::HaveInsertPoint
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
Definition: CodeGenFunction.h:2469
clang::CodeGen::CodeGenFunction::getDestroyer
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:2093
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::EmitVAArg
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
Definition: CGCall.cpp:5672
clang::CodeGen::CodeGenFunction::EmitStoreOfScalar
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
Definition: CodeGenFunction.h:3851
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::ArrayInitLoopExpr
Represents a loop initializing the elements of an array.
Definition: Expr.h:5426
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3856
clang::CodeGen::CodeGenFunction::TCK_Store
@ TCK_Store
Checking the destination of a store. Must be suitably sized and aligned.
Definition: CodeGenFunction.h:2955
clang::CodeGen::CodeGenFunction::EmitObjCMessageExpr
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
Definition: CGObjC.cpp:574
clang::CXXBindTemporaryExpr::getTemporary
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1437
clang::CodeGen::CGBuilderTy
Definition: CGBuilder.h:45
clang::CodeGen::CGBuilderTy::CreateStructGEP
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:192
ConstantEmitter.h
clang::CodeGen::CodeGenFunction::pushLifetimeExtendedDestroy
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
Definition: CGDecl.cpp:2140
clang::CodeGen::AggValueSlot::setExternallyDestructed
void setExternallyDestructed(bool destructed=true)
Definition: CGValue.h:598
clang::InitListExpr::isTransparent
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition: Expr.cpp:2408
clang::Expr::isGLValue
bool isGLValue() const
Definition: Expr.h:273
clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
Definition: CGExpr.cpp:2084
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:269
CK_Greater
@ CK_Greater
Definition: CGExprAgg.cpp:953
clang::ComparisonCategoryInfo::getUnordered
const ValueInfo * getUnordered() const
Definition: ComparisonCategories.h:167
clang::Type::hasFloatingRepresentation
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
Definition: Type.cpp:2131
clang::OpaqueValueExpr
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1144
clang::CodeGen::CodeGenFunction::CXXDefaultInitExprScope
The scope of a CXXDefaultInitExpr.
Definition: CodeGenFunction.h:1620
clang::Type::hasSignedIntegerRepresentation
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition: Type.cpp:2059
clang::CodeGen::NormalEHLifetimeMarker
@ NormalEHLifetimeMarker
Definition: EHScopeStack.h:89
clang::CXXThrowExpr
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1188
clang::CodeGen::CodeGenFunction::getOverlapForFieldInit
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
Definition: CGExprAgg.cpp:2017
clang::CodeGen::CodeGenFunction::pushFullExprCleanup
void pushFullExprCleanup(CleanupKind kind, As... A)
pushFullExprCleanup - Push a cleanup to be run at the end of the current full-expression.
Definition: CodeGenFunction.h:770
clang::ASTContext::getTypeAlignInChars
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
Definition: ASTContext.cpp:2524
clang::Type::isCUDADeviceBuiltinTextureType
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition: Type.cpp:4436
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:357
EmitCompare
static llvm::Value * EmitCompare(CGBuilderTy &Builder, CodeGenFunction &CGF, const BinaryOperator *E, llvm::Value *LHS, llvm::Value *RHS, CompareKind Kind, const char *NameSuffix="")
Definition: CGExprAgg.cpp:957
clang::CodeGen::AggValueSlot::IsZeroed
@ IsZeroed
Definition: CGValue.h:552
clang::TypeInfo
Definition: ASTContext.h:179
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6895
V
#define V(N, I)
Definition: ASTContext.h:3235
clang::IntegerLiteral
Definition: Expr.h:1503
clang::ast_matchers::atomicType
const AstTypeMatcher< AtomicType > atomicType
Matches atomic types.
Definition: ASTMatchersInternal.cpp:1043
clang::CodeGen::CodeGenFunction::EmitCXXConstructExpr
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
Definition: CGExprCXX.cpp:585
clang::CallExpr::getCallReturnType
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1575
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::AggValueSlot::setVolatile
void setVolatile(bool flag)
Definition: CGValue.h:608
clang::FloatingLiteral
Definition: Expr.h:1648
clang::CodeGen::TBAAAccessInfo
Definition: CodeGenTBAA.h:41
clang::CodeGen::CodeGenFunction::hasScalarEvaluationKind
static bool hasScalarEvaluationKind(QualType T)
Definition: CodeGenFunction.h:2419
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
DeclTemplate.h
clang::CodeGen::AggValueSlot::setZeroed
void setZeroed(bool V=true)
Definition: CGValue.h:659
clang::CodeGen::CGCXXABI::EmitMemberPointerComparison
virtual llvm::Value * EmitMemberPointerComparison(CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)
Emit a comparison between two member pointers. Returns an i1.
Definition: CGCXXABI.cpp:80
clang::CXXRewrittenBinaryOperator
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:284
clang::CodeGen::AggValueSlot::asRValue
RValue asRValue() const
Definition: CGValue.h:651
clang::ASTContext::getAsConstantArrayType
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2726
clang::CodeGen::CodeGenModule::getObjCRuntime
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
Definition: CodeGenModule.h:613
clang::CodeGen::AggValueSlot::ignored
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Definition: CGValue.h:559
clang::CXXBindTemporaryExpr
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1419
clang::ComparisonCategoryInfo::Record
const CXXRecordDecl * Record
The declaration for the comparison category type from the standard library.
Definition: ComparisonCategories.h:118
clang::QualType::getAddressSpace
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6756
clang::ParenExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:2136
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3812
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
clang::Type::isNullPtrType
bool isNullPtrType() const
Definition: Type.h:7205
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1872
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::CodeGen::CodeGenModule::isPaddedAtomicType
bool isPaddedAtomicType(QualType type)
Definition: CodeGenTypes.cpp:835
clang::CodeGen::CodeGenFunction::CreateAggTemp
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
Definition: CodeGenFunction.h:2613
clang::ASTContext::getAsArrayType
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Definition: ASTContext.cpp:6873
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
clang::SubstNonTypeTemplateParmExpr::getReplacement
Expr * getReplacement() const
Definition: ExprCXX.h:4307
clang::TargetInfo::getPointerWidth
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition: TargetInfo.h:441
clang::CodeGen::LValue::isBitField
bool isBitField() const
Definition: CGValue.h:267
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:731
clang::CodeGen::Address::getType
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:99
clang::ASTContext::getTypeInfoDataSizeInChars
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
Definition: ASTContext.cpp:1853
clang::MaterializeTemporaryExpr
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4513
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ASTContext::getSizeType
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Definition: ASTContext.cpp:5933
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3012
clang::CodeGen::RValue::isAggregate
bool isAggregate() const
Definition: CGValue.h:56
clang::CXXInheritedCtorInitExpr::constructsVBase
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1697
clang::CodeGen::TEK_Complex
@ TEK_Complex
Definition: CodeGenFunction.h:108
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::CodeGen::CodeGenFunction::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenFunction.h:2026
clang::QualType::DK_none
@ DK_none
Definition: Type.h:1276
clang::CodeGen::CodeGenFunction::EmitAtomicExpr
RValue EmitAtomicExpr(AtomicExpr *E)
Definition: CGAtomic.cpp:806
clang::StmtVisitorBase< std::add_pointer, ImplClass, void, ParamTys... >::Visit
void Visit(PTR(Stmt) S, ParamTys... P)
Definition: StmtVisitor.h:43
clang::CodeGen::CodeGenFunction::pushRegularPartialArrayCleanup
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
Definition: CGDecl.cpp:2395
clang::ASTRecordLayout::getNonVirtualSize
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
Definition: RecordLayout.h:210
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
Definition: CodeGenFunction.cpp:1691
clang::PseudoObjectExpr
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6105
clang::CharUnits::One
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition: CharUnits.h:58
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:732
clang::index::SymbolKind::Field
@ Field
clang::CodeGen::CodeGenFunction::CallLifetimeEnd
Definition: CodeGenFunction.h:625
clang::CodeGen::CodeGenFunction::callCStructMoveAssignmentOperator
void callCStructMoveAssignmentOperator(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:923
clang::CodeGen::CodeGenFunction::getCleanupKind
CleanupKind getCleanupKind(QualType::DestructionKind kind)
Definition: CodeGenFunction.h:2092
clang::AbstractConditionalOperator::getFalseExpr
Expr * getFalseExpr() const
Definition: Expr.h:4302
clang::CXXStdInitializerListExpr::getSubExpr
Expr * getSubExpr()
Definition: ExprCXX.h:814
clang::LambdaExpr::const_capture_init_iterator
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition: ExprCXX.h:1985
clang::CodeGen::LValue::getType
QualType getType() const
Definition: CGValue.h:278
clang::ImplicitValueInitExpr
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5515
clang::CodeGen::AggValueSlot::MayOverlap
@ MayOverlap
Definition: CGValue.h:553
clang::CodeGen::CodeGenFunction::needsEHCleanup
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
Definition: CodeGenFunction.h:2077
ASTContext.h
clang::ASTContext::CompCategories
ComparisonCategories CompCategories
Types and expressions required to build C++2a three-way comparisons using operator<=>,...
Definition: ASTContext.h:2244
clang::interp::Zero
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1122
clang::OpaqueValueExpr::getSourceExpr
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1194
clang::CodeGen::CodeGenFunction::EmitLambdaVLACapture
void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV)
Definition: CodeGenFunction.h:2226
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1776
clang::CodeGen::CodeGenFunction::EmitInheritedCXXConstructorCall
void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, bool ForVirtualBase, Address This, bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E)
Emit a call to a constructor inherited from a base class, passing the current constructor's arguments...
Definition: CGClass.cpp:2271
clang::dataflow::var
static constexpr Variable var(Literal L)
Returns the variable of L.
Definition: WatchedLiteralsSolver.cpp:71
clang::CodeGen::AggValueSlot::isPotentiallyAliased
IsAliased_t isPotentiallyAliased() const
Definition: CGValue.h:639
clang::CodeGen::CodeGenFunction::EmitAtomicLoad
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
Definition: CGAtomic.cpp:1609
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3366
CheckAggExprForMemSetUse
static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, CodeGenFunction &CGF)
CheckAggExprForMemSetUse - If the initializer is large and has a lot of zeros in it,...
Definition: CGExprAgg.cpp:1948
clang::TagDecl::isUnion
bool isUnion() const
Definition: Decl.h:3629
clang::CodeGen::AggValueSlot::IsDestructed
@ IsDestructed
Definition: CGValue.h:551
clang::CodeGen::CodeGenFunction::EmitCompoundStmt
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
Definition: CGStmt.cpp:477
clang::CodeGen::CodeGenFunction::EmitCXXTemporary
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
Definition: CGCleanup.cpp:1321
findPeephole
static Expr * findPeephole(Expr *op, CastKind kind, const ASTContext &ctx)
Attempt to look through various unimportant expressions to find a cast of the given kind.
Definition: CGExprAgg.cpp:692
clang::CodeGen::CodeGenFunction::EmitAggExprToLValue
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
Definition: CGExprAgg.cpp:2005
clang::Type::isAnyComplexType
bool isAnyComplexType() const
Definition: Type.h:6981
clang::Type::isAtomicType
bool isAtomicType() const
Definition: Type.h:7024
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1984
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
clang::CodeGen::CodeGenFunction::callCStructCopyAssignmentOperator
void callCStructCopyAssignmentOperator(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:898
clang::CodeGen::CodeGenFunction::incrementProfileCounter
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Definition: CodeGenFunction.h:1528
clang::CodeGen::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
CodeGenModule.h
clang::CodeGen::RValue::isComplex
bool isComplex() const
Definition: CGValue.h:55
clang::CXXInheritedCtorInitExpr
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1658
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1248
clang::CodeGen::CodeGenFunction::getEvaluationKind
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Definition: CodeGenFunction.cpp:218
clang::AtomicType::getValueType
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6451
clang::CodeGen::CodeGenFunction::ConditionalEvaluation
An object to manage conditionally-evaluated expressions.
Definition: CodeGenFunction.h:1184
clang::ConstantExpr
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1041
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
clang::CodeGen::CodeGenFunction::EmitCallExpr
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
Definition: CGExpr.cpp:4970
clang::CastExpr::getCastKind
CastKind getCastKind() const
Definition: Expr.h:3524
clang::CodeGen::CodeGenTypes::isPointerZeroInitializable
bool isPointerZeroInitializable(QualType T)
Check if the pointer type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
Definition: CodeGenTypes.cpp:925
clang::ChooseExpr
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4529
clang::CodeGen::LValue::getTBAAInfo
TBAAAccessInfo getTBAAInfo() const
Definition: CGValue.h:322
clang::ASTContext::getTargetAddressSpace
unsigned getTargetAddressSpace(LangAS AS) const
Definition: ASTContext.cpp:12230
clang::CodeGen::CodeGenFunction::callCStructMoveConstructor
void callCStructMoveConstructor(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:911
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::CXXRecordDecl::isEmpty
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1150
clang::FullExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1026
clang::CodeGen::CodeGenFunction::LValueIsSuitableForInlineAtomic
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
Definition: CGAtomic.cpp:1596
clang::CharacterLiteral
Definition: Expr.h:1593
isSimpleZero
static bool isSimpleZero(const Expr *E, CodeGenFunction &CGF)
isSimpleZero - If emitting this value will obviously just cause a store of zero to memory,...
Definition: CGExprAgg.cpp:1495
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
clang::ComparisonCategoryInfo
Definition: ComparisonCategories.h:75
clang::FieldDecl::getFieldIndex
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:4343
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:734
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7453
clang::CompoundLiteralExpr
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3410
Emitter
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:797
clang::CodeGen::CodeGenFunction::EmitCheckedLValue
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
Definition: CGExpr.cpp:1236
clang::ASTRecordLayout
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
clang::CodeGen::CodeGenFunction::EmitPseudoObjectLValue
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
Definition: CGExpr.cpp:5635
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::CodeGen::CodeGenFunction::getOverlapForBaseInit
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual)
Determine whether a base class initialization may overlap some other object.
Definition: CGExprAgg.cpp:2035
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:619
clang::CodeGen::LValue::isSimple
bool isSimple() const
Definition: CGValue.h:265
GetNumNonZeroBytesInInit
static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CodeGenFunction &CGF)
GetNumNonZeroBytesInInit - Get an approximate count of the number of non-zero bytes that will be stor...
Definition: CGExprAgg.cpp:1886
clang::DesignatedInitUpdateExpr
Definition: Expr.h:5372
clang::CodeGen::CodeGenFunction::getTargetHooks
const TargetCodeGenInfo & getTargetHooks() const
Definition: CodeGenFunction.h:2028
clang::CodeGen::AggValueSlot::forAddr
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
Definition: CGValue.h:574
clang::QualType::isTriviallyCopyableType
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2469
clang::Type::isMemberPointerType
bool isMemberPointerType() const
Definition: Type.h:6931
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6883
clang::CodeGen::CodeGenFunction::StmtExprEvaluation
An RAII object to record that we're evaluating a statement expression.
Definition: CodeGenFunction.h:1223
clang::syntax::NodeRole::Size
@ Size
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:1023
clang::LambdaExpr::capture_init_end
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression.
Definition: ExprCXX.h:2011
clang::ChooseExpr::getChosenSubExpr
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition: Expr.h:4565
clang::DesignatedInitUpdateExpr::getUpdater
InitListExpr * getUpdater() const
Definition: Expr.h:5394
CK_Less
@ CK_Less
Definition: CGExprAgg.cpp:952
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:93
clang::CodeGen::CodeGenModule::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenModule.cpp:1075
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
clang::ComplexType
Complex values, per C99 6.2.5p11.
Definition: Type.h:2716
clang::CodeGen::CodeGenFunction::pushDestroy
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
Definition: CGDecl.cpp:2120
clang::LangOptions::NonGC
@ NonGC
Definition: LangOptions.h:86
clang::CXXDefaultInitExpr::getExpr
const Expr * getExpr() const
Get the initialization expression that will be used.
Definition: ExprCXX.h:1353
clang::BinaryOperator::getLHS
Expr * getLHS() const
Definition: Expr.h:3861
clang::ParenExpr
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2121
clang::CoyieldExpr
Represents a 'co_yield' expression.
Definition: ExprCXX.h:4904
clang::CodeGen::CodeGenTypeCache::PtrDiffTy
llvm::IntegerType * PtrDiffTy
Definition: CodeGenTypeCache.h:51
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:742
clang::CodeGen::AggValueSlot::IsNotAliased
@ IsNotAliased
Definition: CGValue.h:550
clang::Expr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:329
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:279
clang::RecordDecl::fields
field_range fields() const
Definition: Decl.h:4209
clang::CodeGen::AggValueSlot::IsAliased
@ IsAliased
Definition: CGValue.h:550
clang::CodeGen::AggValueSlot::NeedsGCBarriers
@ NeedsGCBarriers
Definition: CGValue.h:554
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4354
clang::CodeGen::CodeGenFunction::EmitScalarInit
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition: CGDecl.cpp:776
Value
Value
Definition: UninitializedValues.cpp:103
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::CXXRecordDecl::hasTrivialMoveConstructor
bool hasTrivialMoveConstructor() const
Determine whether this class has a trivial move constructor (C++11 [class.copy]p12)
Definition: DeclCXX.h:1258
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:90
clang::CodeGen::CGBuilderTy::CreateAlignedLoad
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition: CGBuilder.h:89
clang::CodeGen::AggValueSlot::forLValue
static AggValueSlot forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
Definition: CGValue.h:587
clang::ArraySubscriptExpr
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2654
clang::CodeGen::AggValueSlot::isVolatile
bool isVolatile() const
Definition: CGValue.h:604
StmtVisitor.h
clang::CodeGen::CodeGenFunction::TCK_Load
@ TCK_Load
Checking the operand of a load. Must be suitably sized and aligned.
Definition: CodeGenFunction.h:2953
clang::QualType::isPODType
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2361
clang::ArrayInitLoopExpr::getSubExpr
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:5446
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1275
clang::InitListExpr::getArrayFiller
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4892
clang::CodeGen::CodeGenFunction::getTypes
CodeGenTypes & getTypes() const
Definition: CodeGenFunction.h:1983
clang::CoawaitExpr
Represents a 'co_await' expression.
Definition: ExprCXX.h:4823
clang::CodeGen::AggValueSlot
An aggregate value slot.
Definition: CGValue.h:491
clang::ComparisonCategoryInfo::isPartial
bool isPartial() const
True iff the comparison is not totally ordered.
Definition: ComparisonCategories.h:143
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:214
clang::RecordDecl::hasObjectMember
bool hasObjectMember() const
Definition: Decl.h:4064
clang::CXXRecordDecl::hasTrivialMoveAssignment
bool hasTrivialMoveAssignment() const
Determine whether this class has a trivial move assignment operator (C++11 [class....
Definition: DeclCXX.h:1298
clang::CodeGen::RValue::getComplexVal
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
Definition: CGValue.h:68
clang::CodeGen::CodeGenFunction::hasAggregateEvaluationKind
static bool hasAggregateEvaluationKind(QualType T)
Definition: CodeGenFunction.h:2423
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:2490
clang::CXXInheritedCtorInitExpr::inheritedFromVBase
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition: ExprCXX.h:1707
clang::ExprValueKind
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:120
clang::CodeGen::CodeGenModule::DecorateInstructionWithTBAA
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
Definition: CodeGenModule.cpp:1056
clang::CodeGen::LValue::getPointer
llvm::Value * getPointer(CodeGenFunction &CGF) const
Definition: CGValue.h:337
clang::CodeGen::CodeGenFunction::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenFunction.cpp:1911
clang::RecordDecl::field_end
field_iterator field_end() const
Definition: Decl.h:4212
clang::CodeGen::CGBuilderTy::CreateElementBitCast
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
Definition: CGBuilder.h:168
clang::CodeGen::CodeGenFunction::EmitScalarExpr
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
Definition: CGExprScalar.cpp:5041
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2960
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::CodeGen::AggValueSlot::Overlap_t
Overlap_t
Definition: CGValue.h:553
CGCXXABI.h
clang::CodeGen::AggValueSlot::isIgnored
bool isIgnored() const
Definition: CGValue.h:631
clang::CodeGen::CodeGenFunction::EmitLifetimeStart
llvm::Value * EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
Definition: CGDecl.cpp:1334
clang::PredefinedExpr
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1968
clang::LangAS::Default
@ Default
clang::LambdaExpr::getLambdaClass
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1256
clang::CodeGen::CodeGenFunction::EmitPointerToDataMemberBinaryExpr
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
Definition: CGExpr.cpp:5503
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:261
clang::Expr::HasSideEffects
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition: Expr.cpp:3503
clang::ComparisonCategoryInfo::getEqualOrEquiv
const ValueInfo * getEqualOrEquiv() const
Definition: ComparisonCategories.h:158
clang::CodeGen::TEK_Scalar
@ TEK_Scalar
Definition: CodeGenFunction.h:107
clang::CompoundLiteralExpr::getInitializer
const Expr * getInitializer() const
Definition: Expr.h:3433
clang::AbstractConditionalOperator::getCond
Expr * getCond() const
Definition: Expr.h:4290
clang::UnaryOperator::getSubExpr
Expr * getSubExpr() const
Definition: Expr.h:2219
clang::CodeGen::CodeGenFunction::getOrCreateOpaqueLValueMapping
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
Definition: CGExpr.cpp:4915
clang::FieldDecl::getParent
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition: Decl.h:3122
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3031
clang
Definition: CalledOnceCheck.h:17
clang::InitListExpr::getInitializedFieldInUnion
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4910
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:6949
clang::interp::GE
bool GE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:519
clang::ASTContext::toCharUnitsFromBits
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Definition: ASTContext.cpp:2504
clang::CodeGen::CodeGenFunction::EmitAggregateCopy
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
Definition: CGExprAgg.cpp:2056
clang::TypeInfoChars
Definition: ASTContext.h:193
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::CodeGen::RValue::getAggregatePointer
llvm::Value * getAggregatePointer() const
Definition: CGValue.h:79
clang::CodeGen::AggValueSlot::getAddress
Address getAddress() const
Definition: CGValue.h:627
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3863
clang::GenericSelectionExpr
Represents a C11 generic selection.
Definition: Expr.h:5633
clang::CXXScalarValueInitExpr
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2100
clang::CodeGen::AggValueSlot::isExternallyDestructed
IsDestructed_t isExternallyDestructed() const
Definition: CGValue.h:595
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::CodeGen::CodeGenFunction::ArrayInitLoopExprScope
The scope of an ArrayInitLoopExpr.
Definition: CodeGenFunction.h:1648
clang::CodeGen::AggValueSlot::getQualifiers
Qualifiers getQualifiers() const
Definition: CGValue.h:602
clang::CodeGen::CodeGenFunction::hasVolatileMember
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
Definition: CodeGenFunction.h:2670
clang::CodeGen::RValue::isScalar
bool isScalar() const
Definition: CGValue.h:54
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::ASTContext::getASTRecordLayout
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
Definition: RecordLayoutBuilder.cpp:3275
CompareKind
CompareKind
Definition: CGExprAgg.cpp:951
clang::VAArgExpr
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4638
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3169
clang::CodeGen::CodeGenFunction::EmitLValue
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
Definition: CGExpr.cpp:1272
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4826
clang::InitListExpr::getInit
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4844
clang::ComparisonCategoryInfo::ValueInfo
Definition: ComparisonCategories.h:84
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::ASTContext::getTypeInfoInChars
TypeInfoChars getTypeInfoInChars(const Type *T) const
Definition: ASTContext.cpp:1889
clang::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::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2544
clang::AtomicType
Definition: Type.h:6440
clang::CXXRecordDecl::hasTrivialCopyConstructor
bool hasTrivialCopyConstructor() const
Determine whether this class has a trivial copy constructor (C++ [class.copy]p6, C++11 [class....
Definition: DeclCXX.h:1235
clang::CXXStdInitializerListExpr
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:798
clang::CodeGen::CodeGenFunction::FieldConstructionScope
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
Definition: CodeGenFunction.h:1603
CK_Equal
@ CK_Equal
Definition: CGExprAgg.cpp:954
clang::CodeGen::CodeGenFunction::GetAddressOfDirectBaseInCompleteClass
Address GetAddressOfDirectBaseInCompleteClass(Address Value, const CXXRecordDecl *Derived, const CXXRecordDecl *Base, bool BaseIsVirtual)
GetAddressOfBaseOfCompleteClass - Convert the given pointer to a complete class to the given direct b...
Definition: CGClass.cpp:219
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
clang::CastKind
CastKind
CastKind - The kind of operation required for a conversion.
Definition: OperationKinds.h:20
clang::CodeGen::CodeGenFunction::CreateMemTemp
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Definition: CGExpr.cpp:135
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2571
clang::ArrayType::getElementType
QualType getElementType() const
Definition: Type.h:3033
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::AggValueSlot::IsNotDestructed
@ IsNotDestructed
Definition: CGValue.h:551
clang::CodeGen::AggValueSlot::getPreferredSize
CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const
Get the preferred size to use when storing a value to this slot.
Definition: CGValue.h:667
clang::CXXDefaultInitExpr
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1325
clang::QualType::isDestructedType
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1287
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::ComparisonCategoryInfo::getLess
const ValueInfo * getLess() const
Definition: ComparisonCategories.h:161
clang::InitListExpr::hadArrayRangeDesignator
bool hadArrayRangeDesignator() const
Definition: Expr.h:4968
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3480
clang::ComparisonCategoryInfo::getGreater
const ValueInfo * getGreater() const
Definition: ComparisonCategories.h:164
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::CodeGen::CGBuilderTy::CreateMemSet
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:341
clang::Type::isCUDADeviceBuiltinSurfaceType
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition: Type.cpp:4429
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3983
clang::format::cleanup
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
Definition: Format.cpp:3494
clang::CXXRecordDecl::hasTrivialCopyAssignment
bool hasTrivialCopyAssignment() const
Determine whether this class has a trivial copy assignment operator (C++ [class.copy]p11,...
Definition: DeclCXX.h:1285
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2810
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:563
clang::CodeGen::AggValueSlot::NeedsGCBarriers_t
NeedsGCBarriers_t
Definition: CGValue.h:554
clang::diag::kind
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:62
clang::InitListExpr::getNumInits
unsigned getNumInits() const
Definition: Expr.h:4826
clang::CodeGen::CodeGenFunction::EmitLValueForFieldInitialization
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
Definition: CGExpr.cpp:4511
clang::CXXConstructExpr
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1467
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
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:1997
clang::ArrayInitLoopExpr::getCommonExpr
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:5441
clang::OpaqueValueExpr::isUnique
bool isUnique() const
Definition: Expr.h:1202
clang::CodeGen::CodeGenModule::mergeTBAAInfoForMemoryTransfer
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, TBAAAccessInfo SrcInfo)
mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the purposes of memory transfer call...
Definition: CodeGenModule.cpp:1049
clang::CodeGen::CodeGenFunction::EmitCXXThrowExpr
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Definition: CGException.cpp:441
clang::Type::isIntegralOrEnumerationType
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:7283
clang::CodeGen::RValue::getAggregateAddress
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
Definition: CGValue.h:73
clang::LambdaExpr::capture_init_begin
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
Definition: ExprCXX.h:1999
clang::CodeGen::LValue::setNonGC
void setNonGC(bool Value)
Definition: CGValue.h:291
clang::CodeGen::AggValueSlot::DoesNotOverlap
@ DoesNotOverlap
Definition: CGValue.h:553
clang::CodeGen::CodeGenModule::getTBAAStructInfo
llvm::MDNode * getTBAAStructInfo(QualType QTy)
Definition: CodeGenModule.cpp:1015