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