21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/GlobalVariable.h"
24 #include "llvm/IR/Intrinsics.h"
25 using namespace clang;
26 using namespace CodeGen;
33 class AggExprEmitter :
public StmtVisitor<AggExprEmitter> {
44 bool shouldUseDestForReturnSlot()
const {
45 return !(Dest.requiresGCollection() || Dest.isPotentiallyAliased());
49 if (!shouldUseDestForReturnSlot())
57 if (!Dest.isIgnored())
return Dest;
58 return CGF.CreateAggTemp(T,
"agg.tmp.ensured");
61 if (!Dest.isIgnored())
return;
62 Dest = CGF.CreateAggTemp(T,
"agg.tmp.ensured");
68 IsResultUnused(IsResultUnused) { }
77 void EmitAggLoadOfLValue(
const Expr *
E);
85 void EmitMoveFromReturnSlot(
const Expr *
E,
RValue Src);
87 void EmitArrayInit(
Address DestPtr, llvm::ArrayType *AType,
91 if (CGF.getLangOpts().getGC() && TypeRequiresGCollection(T))
96 bool TypeRequiresGCollection(
QualType T);
102 void Visit(
Expr *
E) {
107 void VisitStmt(
Stmt *
S) {
108 CGF.ErrorUnsupported(S,
"aggregate expression");
129 = CGF.tryEmitAsConstant(E)) {
130 EmitFinalDestCopy(E->
getType(), result.getReferenceLValue(CGF, E));
135 EmitAggLoadOfLValue(E);
138 void VisitMemberExpr(
MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
139 void VisitUnaryDeref(
UnaryOperator *E) { EmitAggLoadOfLValue(E); }
140 void VisitStringLiteral(
StringLiteral *E) { EmitAggLoadOfLValue(E); }
143 EmitAggLoadOfLValue(E);
146 EmitAggLoadOfLValue(E);
151 void VisitCallExpr(
const CallExpr *E);
152 void VisitStmtExpr(
const StmtExpr *E);
154 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *BO);
160 EmitAggLoadOfLValue(E);
183 void VisitCXXTypeidExpr(
CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
189 LValue LV = CGF.EmitPseudoObjectLValue(E);
190 return EmitFinalDestCopy(E->
getType(), LV);
193 CGF.EmitPseudoObjectRValue(E, EnsureSlot(E->
getType()));
201 void VisitCXXThrowExpr(
const CXXThrowExpr *E) { CGF.EmitCXXThrowExpr(E); }
203 RValue Res = CGF.EmitAtomicExpr(E);
204 EmitFinalDestCopy(E->
getType(), Res);
216 void AggExprEmitter::EmitAggLoadOfLValue(
const Expr *E) {
217 LValue LV = CGF.EmitLValue(E);
221 CGF.EmitAtomicLoad(LV, E->
getExprLoc(), Dest);
225 EmitFinalDestCopy(E->
getType(), LV);
229 bool AggExprEmitter::TypeRequiresGCollection(
QualType T) {
232 if (!RecordTy)
return false;
236 if (isa<CXXRecordDecl>(Record) &&
237 (cast<CXXRecordDecl>(Record)->hasNonTrivialCopyConstructor() ||
238 !cast<CXXRecordDecl>(Record)->hasTrivialDestructor()))
255 void AggExprEmitter::EmitMoveFromReturnSlot(
const Expr *E,
RValue src) {
256 if (shouldUseDestForReturnSlot()) {
265 EmitFinalDestCopy(E->
getType(), src);
270 assert(src.
isAggregate() &&
"value must be aggregate value!");
272 EmitFinalDestCopy(type, srcLV);
276 void AggExprEmitter::EmitFinalDestCopy(
QualType type,
const LValue &src) {
281 if (Dest.isIgnored())
287 EmitCopy(type, Dest, srcAgg);
297 CharUnits sz = CGF.getContext().getTypeSizeInChars(type);
299 CGF.CGM.getObjCRuntime().EmitGCMemmoveCollectable(CGF,
321 assert(Array.
isSimple() &&
"initializer_list array not a simple lvalue");
326 assert(ArrayType &&
"std::initializer_list constructed from non-array");
332 CGF.ErrorUnsupported(E,
"weird std::initializer_list");
337 if (!Field->getType()->isPointerType() ||
338 !Ctx.
hasSameType(Field->getType()->getPointeeType(),
340 CGF.ErrorUnsupported(E,
"weird std::initializer_list");
346 LValue Start = CGF.EmitLValueForFieldInitialization(DestLV, *Field);
347 llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0);
350 Builder.CreateInBoundsGEP(ArrayPtr.getPointer(), IdxStart,
"arraystart");
351 CGF.EmitStoreThroughLValue(
RValue::get(ArrayStart), Start);
355 CGF.ErrorUnsupported(E,
"weird std::initializer_list");
360 LValue EndOrLength = CGF.EmitLValueForFieldInitialization(DestLV, *Field);
361 if (Field->getType()->isPointerType() &&
362 Ctx.
hasSameType(Field->getType()->getPointeeType(),
367 Builder.CreateInBoundsGEP(ArrayPtr.getPointer(), IdxEnd,
"arrayend");
368 CGF.EmitStoreThroughLValue(
RValue::get(ArrayEnd), EndOrLength);
371 CGF.EmitStoreThroughLValue(
RValue::get(Size), EndOrLength);
373 CGF.ErrorUnsupported(E,
"weird std::initializer_list");
384 if (isa<ImplicitValueInitExpr>(E))
387 if (
auto *ILE = dyn_cast<InitListExpr>(E)) {
388 if (ILE->getNumInits())
393 if (
auto *Cons = dyn_cast_or_null<CXXConstructExpr>(E))
394 return Cons->getConstructor()->isDefaultConstructor() &&
395 Cons->getConstructor()->isTrivial();
402 void AggExprEmitter::EmitArrayInit(
Address DestPtr, llvm::ArrayType *AType,
406 uint64_t NumArrayElements = AType->getNumElements();
407 assert(NumInitElements <= NumArrayElements);
411 llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
416 CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
426 llvm::Instruction *cleanupDominator =
nullptr;
427 if (CGF.needsEHCleanup(dtorKind)) {
432 endOfInit = CGF.CreateTempAlloca(begin->getType(), CGF.getPointerAlign(),
433 "arrayinit.endOfInit");
434 cleanupDominator =
Builder.CreateStore(begin, endOfInit);
435 CGF.pushIrregularPartialArrayCleanup(begin, endOfInit, elementType,
437 CGF.getDestroyer(dtorKind));
438 cleanup = CGF.EHStack.stable_begin();
445 llvm::Value *one = llvm::ConstantInt::get(CGF.SizeTy, 1);
455 for (uint64_t i = 0; i != NumInitElements; ++i) {
458 element =
Builder.CreateInBoundsGEP(element, one,
"arrayinit.element");
467 CGF.MakeAddrLValue(
Address(element, elementAlign), elementType);
468 EmitInitializationToLValue(E->
getInit(i), elementLV);
478 if (NumInitElements != NumArrayElements &&
479 !(Dest.
isZeroed() && hasTrivialFiller &&
480 CGF.getTypes().isZeroInitializable(elementType))) {
486 if (NumInitElements) {
487 element =
Builder.CreateInBoundsGEP(element, one,
"arrayinit.start");
493 llvm::ConstantInt::get(CGF.SizeTy, NumArrayElements),
496 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
497 llvm::BasicBlock *bodyBB = CGF.createBasicBlock(
"arrayinit.body");
500 CGF.EmitBlock(bodyBB);
501 llvm::PHINode *currentElement =
502 Builder.CreatePHI(element->getType(), 2,
"arrayinit.cur");
503 currentElement->addIncoming(element, entryBB);
507 CGF.MakeAddrLValue(
Address(currentElement, elementAlign), elementType);
509 EmitInitializationToLValue(filler, elementLV);
511 EmitNullInitializationToLValue(elementLV);
515 Builder.CreateInBoundsGEP(currentElement, one,
"arrayinit.next");
518 if (endOfInit.
isValid())
Builder.CreateStore(nextElement, endOfInit);
523 llvm::BasicBlock *endBB = CGF.createBasicBlock(
"arrayinit.end");
524 Builder.CreateCondBr(done, endBB, bodyBB);
525 currentElement->addIncoming(nextElement,
Builder.GetInsertBlock());
527 CGF.EmitBlock(endBB);
531 if (dtorKind) CGF.DeactivateCleanupBlock(cleanup, cleanupDominator);
543 EmitFinalDestCopy(e->
getType(), CGF.getOpaqueLValueMapping(e));
552 EmitAggLoadOfLValue(E);
565 if (
CastExpr *castE = dyn_cast<CastExpr>(op)) {
566 if (castE->getCastKind() ==
kind)
567 return castE->getSubExpr();
568 if (castE->getCastKind() == CK_NoOp)
575 void AggExprEmitter::VisitCastExpr(
CastExpr *E) {
576 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
577 CGF.CGM.EmitExplicitCastExprType(ECE, &CGF);
581 assert(isa<CXXDynamicCastExpr>(E) &&
"CK_Dynamic without a dynamic_cast?");
586 CGF.EmitDynamicCast(LV.
getAddress(), cast<CXXDynamicCastExpr>(
E));
588 CGF.CGM.ErrorUnsupported(E,
"non-simple lvalue dynamic_cast");
591 CGF.CGM.ErrorUnsupported(E,
"lvalue dynamic_cast with a destination");
608 CGF.MakeAddrLValue(CastPtr, Ty));
612 case CK_DerivedToBase:
613 case CK_BaseToDerived:
614 case CK_UncheckedDerivedToBase: {
615 llvm_unreachable(
"cannot perform hierarchy conversion in EmitAggExpr: "
616 "should have been unpacked before we got here");
619 case CK_NonAtomicToAtomic:
620 case CK_AtomicToNonAtomic: {
621 bool isToAtomic = (E->
getCastKind() == CK_NonAtomicToAtomic);
626 if (isToAtomic) std::swap(atomicType, valueType);
629 assert(CGF.getContext().hasSameUnqualifiedType(valueType,
634 if (Dest.
isIgnored() || !CGF.CGM.isPaddedAtomicType(atomicType)) {
639 (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
643 assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
645 "peephole significantly changed types?");
653 if (!valueDest.
isIgnored() && CGF.CGM.isPaddedAtomicType(atomicType)) {
657 CGF.EmitNullInitialization(Dest.
getAddress(), atomicType);
661 CGF.Builder.CreateStructGEP(valueDest.
getAddress(), 0,
678 CGF.CreateAggTemp(atomicType,
"atomic-to-nonatomic.temp");
684 return EmitFinalDestCopy(valueType, rvalue);
687 case CK_LValueToRValue:
698 case CK_UserDefinedConversion:
699 case CK_ConstructorConversion:
702 "Implicit cast types must be compatible");
706 case CK_LValueBitCast:
707 llvm_unreachable(
"should not be emitting lvalue bitcast as rvalue");
711 case CK_ArrayToPointerDecay:
712 case CK_FunctionToPointerDecay:
713 case CK_NullToPointer:
714 case CK_NullToMemberPointer:
715 case CK_BaseToDerivedMemberPointer:
716 case CK_DerivedToBaseMemberPointer:
717 case CK_MemberPointerToBoolean:
718 case CK_ReinterpretMemberPointer:
719 case CK_IntegralToPointer:
720 case CK_PointerToIntegral:
721 case CK_PointerToBoolean:
724 case CK_IntegralCast:
725 case CK_BooleanToSignedIntegral:
726 case CK_IntegralToBoolean:
727 case CK_IntegralToFloating:
728 case CK_FloatingToIntegral:
729 case CK_FloatingToBoolean:
730 case CK_FloatingCast:
731 case CK_CPointerToObjCPointerCast:
732 case CK_BlockPointerToObjCPointerCast:
733 case CK_AnyPointerToBlockPointerCast:
734 case CK_ObjCObjectLValueCast:
735 case CK_FloatingRealToComplex:
736 case CK_FloatingComplexToReal:
737 case CK_FloatingComplexToBoolean:
738 case CK_FloatingComplexCast:
739 case CK_FloatingComplexToIntegralComplex:
740 case CK_IntegralRealToComplex:
741 case CK_IntegralComplexToReal:
742 case CK_IntegralComplexToBoolean:
743 case CK_IntegralComplexCast:
744 case CK_IntegralComplexToFloatingComplex:
745 case CK_ARCProduceObject:
746 case CK_ARCConsumeObject:
747 case CK_ARCReclaimReturnedObject:
748 case CK_ARCExtendBlockObject:
749 case CK_CopyAndAutoreleaseBlockObject:
750 case CK_BuiltinFnToFnPtr:
751 case CK_ZeroToOCLEvent:
752 case CK_AddressSpaceConversion:
753 llvm_unreachable(
"cast kind invalid for aggregate types");
757 void AggExprEmitter::VisitCallExpr(
const CallExpr *E) {
759 EmitAggLoadOfLValue(E);
763 RValue RV = CGF.EmitCallExpr(E, getReturnValueSlot());
764 EmitMoveFromReturnSlot(E, RV);
768 RValue RV = CGF.EmitObjCMessageExpr(E, getReturnValueSlot());
769 EmitMoveFromReturnSlot(E, RV);
773 CGF.EmitIgnoredExpr(E->
getLHS());
777 void AggExprEmitter::VisitStmtExpr(
const StmtExpr *E) {
779 CGF.EmitCompoundStmt(*E->
getSubStmt(),
true, Dest);
782 void AggExprEmitter::VisitBinaryOperator(
const BinaryOperator *E) {
784 VisitPointerToDataMemberBinaryOperator(E);
786 CGF.ErrorUnsupported(E,
"aggregate binary expression");
789 void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
791 LValue LV = CGF.EmitPointerToDataMemberBinaryExpr(E);
792 EmitFinalDestCopy(E->
getType(), LV);
802 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
804 return (var && var->hasAttr<BlocksAttr>());
813 if (op->isAssignmentOp() || op->isPtrMemOp())
817 if (op->getOpcode() == BO_Comma)
825 = dyn_cast<AbstractConditionalOperator>(E)) {
831 = dyn_cast<OpaqueValueExpr>(E)) {
832 if (
const Expr *src = op->getSourceExpr())
839 }
else if (
const CastExpr *
cast = dyn_cast<CastExpr>(E)) {
840 if (
cast->getCastKind() == CK_LValueToRValue)
846 }
else if (
const UnaryOperator *uop = dyn_cast<UnaryOperator>(E)) {
850 }
else if (
const MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
864 assert(CGF.getContext().hasSameUnqualifiedType(E->
getLHS()->
getType(),
866 &&
"Invalid assignment");
882 if (LHS.getType()->isAtomicType() ||
883 CGF.LValueIsSuitableForInlineAtomic(LHS)) {
884 CGF.EmitAtomicStore(Dest.
asRValue(), LHS,
false);
901 CGF.LValueIsSuitableForInlineAtomic(LHS)) {
904 CGF.EmitAtomicStore(Dest.
asRValue(), LHS,
false);
918 CGF.EmitAggExpr(E->
getRHS(), LHSSlot);
921 EmitFinalDestCopy(E->
getType(), LHS);
924 void AggExprEmitter::
926 llvm::BasicBlock *LHSBlock = CGF.createBasicBlock(
"cond.true");
927 llvm::BasicBlock *RHSBlock = CGF.createBasicBlock(
"cond.false");
928 llvm::BasicBlock *ContBlock = CGF.createBasicBlock(
"cond.end");
934 CGF.EmitBranchOnBoolExpr(E->
getCond(), LHSBlock, RHSBlock,
935 CGF.getProfileCount(E));
941 CGF.EmitBlock(LHSBlock);
942 CGF.incrementProfileCounter(E);
946 assert(CGF.HaveInsertPoint() &&
"expression evaluation ended with no IP!");
947 CGF.Builder.CreateBr(ContBlock);
956 CGF.EmitBlock(RHSBlock);
960 CGF.EmitBlock(ContBlock);
963 void AggExprEmitter::VisitChooseExpr(
const ChooseExpr *CE) {
967 void AggExprEmitter::VisitVAArgExpr(
VAArgExpr *VE) {
969 Address ArgPtr = CGF.EmitVAArg(VE, ArgValue);
973 CGF.ErrorUnsupported(VE,
"aggregate va_arg expression");
977 EmitFinalDestCopy(VE->
getType(), CGF.MakeAddrLValue(ArgPtr, VE->
getType()));
992 if (!wasExternallyDestructed)
999 CGF.EmitCXXConstructExpr(E, Slot);
1002 void AggExprEmitter::VisitCXXInheritedCtorInitExpr(
1005 CGF.EmitInheritedCXXConstructorCall(
1011 AggExprEmitter::VisitLambdaExpr(
LambdaExpr *E) {
1013 CGF.EmitLambdaExpr(E, Slot);
1017 CGF.enterFullExpression(E);
1025 EmitNullInitializationToLValue(CGF.MakeAddrLValue(Slot.
getAddress(), T));
1031 EmitNullInitializationToLValue(CGF.MakeAddrLValue(Slot.
getAddress(), T));
1042 return IL->getValue() == 0;
1045 return FL->getValue().isPosZero();
1047 if ((isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) &&
1051 if (
const CastExpr *ICE = dyn_cast<CastExpr>(E))
1052 return ICE->getCastKind() == CK_NullToPointer;
1055 return CL->getValue() == 0;
1063 AggExprEmitter::EmitInitializationToLValue(
Expr *E,
LValue LV) {
1070 }
else if (isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(
E)) {
1071 return EmitNullInitializationToLValue(LV);
1072 }
else if (isa<NoInitExpr>(E)) {
1076 RValue RV = CGF.EmitReferenceBindingToExpr(E);
1077 return CGF.EmitStoreThroughLValue(RV, LV);
1080 switch (CGF.getEvaluationKind(type)) {
1082 CGF.EmitComplexExprIntoLValue(E, LV,
true);
1093 CGF.EmitScalarInit(E,
nullptr, LV,
false);
1095 CGF.EmitStoreThroughLValue(
RValue::get(CGF.EmitScalarExpr(E)), LV);
1099 llvm_unreachable(
"bad evaluation kind");
1102 void AggExprEmitter::EmitNullInitializationToLValue(
LValue lv) {
1107 if (Dest.
isZeroed() && CGF.getTypes().isZeroInitializable(type))
1110 if (CGF.hasScalarEvaluationKind(type)) {
1112 llvm::Value *null = CGF.CGM.EmitNullConstant(type);
1116 CGF.EmitStoreThroughBitfieldLValue(
RValue::get(null), lv);
1119 CGF.EmitStoreOfScalar(null, lv,
true);
1129 void AggExprEmitter::VisitInitListExpr(
InitListExpr *E) {
1136 if (llvm::Constant* C = CGF.CGM.EmitConstantExpr(E, E->
getType(), &CGF)) {
1137 llvm::GlobalVariable* GV =
1138 new llvm::GlobalVariable(CGF.CGM.getModule(),
C->getType(),
true,
1140 EmitFinalDestCopy(E->
getType(), CGF.MakeAddrLValue(GV, E->
getType()));
1145 CGF.ErrorUnsupported(E,
"GNU array range designator extension");
1157 CGF.getContext().getAsArrayType(E->
getType())->getElementType();
1160 EmitArrayInit(Dest.
getAddress(), AType, elementType,
E);
1168 CGF.getContext().hasSameUnqualifiedType(E->
getInit(0)->
getType(),
1170 "unexpected list initialization for atomic object");
1186 llvm::Instruction *cleanupDominator =
nullptr;
1188 unsigned curInitIndex = 0;
1191 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(record)) {
1192 assert(E->
getNumInits() >= CXXRD->getNumBases() &&
1193 "missing initializer for base class");
1194 for (
auto &
Base : CXXRD->bases()) {
1195 assert(!
Base.isVirtual() &&
"should not see vbases here");
1196 auto *BaseRD =
Base.getType()->getAsCXXRecordDecl();
1197 Address V = CGF.GetAddressOfDirectBaseInCompleteClass(
1205 CGF.EmitAggExpr(E->
getInit(curInitIndex++), AggSlot);
1208 Base.getType().isDestructedType()) {
1209 CGF.pushDestroy(dtorKind, V,
Base.getType());
1210 cleanups.push_back(CGF.EHStack.stable_begin());
1227 for (
const auto *Field : record->
fields())
1228 assert(Field->isUnnamedBitfield() &&
"Only unnamed bitfields allowed");
1236 LValue FieldLoc = CGF.EmitLValueForFieldInitialization(DestLV, Field);
1237 if (NumInitElements) {
1239 EmitInitializationToLValue(E->
getInit(0), FieldLoc);
1242 EmitNullInitializationToLValue(FieldLoc);
1250 for (
const auto *field : record->
fields()) {
1252 if (field->getType()->isIncompleteArrayType())
1256 if (field->isUnnamedBitfield())
1262 if (curInitIndex == NumInitElements && Dest.
isZeroed() &&
1263 CGF.getTypes().isZeroInitializable(E->
getType()))
1267 LValue LV = CGF.EmitLValueForFieldInitialization(DestLV, field);
1271 if (curInitIndex < NumInitElements) {
1273 EmitInitializationToLValue(E->
getInit(curInitIndex++), LV);
1276 EmitNullInitializationToLValue(LV);
1282 bool pushedCleanup =
false;
1284 = field->getType().isDestructedType()) {
1286 if (CGF.needsEHCleanup(dtorKind)) {
1287 if (!cleanupDominator)
1288 cleanupDominator = CGF.Builder.CreateAlignedLoad(
1290 llvm::Constant::getNullValue(CGF.Int8PtrTy),
1294 CGF.getDestroyer(dtorKind),
false);
1295 cleanups.push_back(CGF.EHStack.stable_begin());
1296 pushedCleanup =
true;
1302 if (!pushedCleanup && LV.
isSimple())
1303 if (llvm::GetElementPtrInst *GEP =
1304 dyn_cast<llvm::GetElementPtrInst>(LV.
getPointer()))
1305 if (GEP->use_empty())
1306 GEP->eraseFromParent();
1311 for (
unsigned i = cleanups.size(); i != 0; --i)
1312 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
1315 if (cleanupDominator)
1316 cleanupDominator->eraseFromParent();
1323 EmitInitializationToLValue(E->
getBase(), DestLV);
1350 if (!RT->isUnionType()) {
1354 unsigned ILEElement = 0;
1355 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(SD))
1356 while (ILEElement != CXXRD->getNumBases())
1359 for (
const auto *Field : SD->
fields()) {
1378 return NumNonZeroBytes;
1384 for (
unsigned i = 0, e = ILE->
getNumInits(); i != e; ++i)
1386 return NumNonZeroBytes;
1403 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
1416 if (NumNonZeroBytes*4 > Size)
1439 "Invalid aggregate expression to emit");
1441 "slot has bits but no address");
1446 AggExprEmitter(*
this, Slot, Slot.
isIgnored()).Visit(const_cast<Expr*>(E));
1462 bool isAssignment) {
1473 "Trying to aggregate-copy a type without a trivial copy/move "
1474 "constructor or assignment operator");
1496 std::pair<CharUnits, CharUnits>
TypeInfo;
1503 if (TypeInfo.first.isZero()) {
1505 if (
auto *VAT = dyn_cast_or_null<VariableArrayType>(
1510 std::pair<CharUnits, CharUnits> LastElementTypeInfo;
1513 assert(!TypeInfo.first.isZero());
1514 SizeVal =
Builder.CreateNUWMul(
1516 llvm::ConstantInt::get(
SizeTy, TypeInfo.first.getQuantity()));
1517 if (!isAssignment) {
1518 SizeVal =
Builder.CreateNUWSub(
1520 llvm::ConstantInt::get(
SizeTy, TypeInfo.first.getQuantity()));
1521 SizeVal =
Builder.CreateNUWAdd(
1522 SizeVal, llvm::ConstantInt::get(
1523 SizeTy, LastElementTypeInfo.first.getQuantity()));
1528 SizeVal = llvm::ConstantInt::get(
SizeTy, TypeInfo.first.getQuantity());
1574 Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
ReturnValueSlot - Contains the address where the return value of a function can be stored...
Defines the clang::ASTContext interface.
unsigned getNumInits() const
CastKind getCastKind() const
A (possibly-)qualified type.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
llvm::Value * getPointer() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
CompoundStmt * getSubStmt()
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
const TargetInfo & getTarget() const
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isRecordType() const
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, llvm::Value *Size)=0
llvm::MDNode * getTBAAStructInfo(QualType QTy)
Address getAddress() const
Defines the C++ template declaration subclasses.
ParenExpr - This represents a parethesized expression, e.g.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
const Expr * getResultExpr() const
The generic selection's result expression.
Represents a call to a C++ constructor.
void setZeroed(bool V=true)
const LangOptions & getLangOpts() const
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
const llvm::APInt & getSize() const
bool hadArrayRangeDesignator() const
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
static Expr * findPeephole(Expr *op, CastKind kind)
Attempt to look through various unimportant expressions to find a cast of the given kind...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
CompoundLiteralExpr - [C99 6.5.2.5].
static bool isSimpleZero(const Expr *E, CodeGenFunction &CGF)
isSimpleZero - If emitting this value will obviously just cause a store of zero to memory...
field_iterator field_begin() const
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
IsZeroed_t isZeroed() const
A C++ throw-expression (C++ [except.throw]).
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
The collection of all-type qualifiers we support.
bool hasTrivialCopyConstructor() const
Determine whether this class has a trivial copy constructor (C++ [class.copy]p6, C++11 [class...
static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CodeGenFunction &CGF)
GetNumNonZeroBytesInInit - Get an approximate count of the number of non-zero bytes that will be stor...
RecordDecl - Represents a struct/union/class.
An object to manage conditionally-evaluated expressions.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isReferenceType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
llvm::IntegerType * SizeTy
Represents a place-holder for an object not to be initialized by anything.
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
static bool isTrivialFiller(Expr *E)
Determine if E is a trivial array filler, that is, one that is equivalent to zero-initialization.
void setNonGC(bool Value)
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Expr * getTrueExpr() const
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...
CharUnits - This is an opaque type for sizes expressed in character units.
field_range fields() const
A builtin binary operation expression such as "x + y" or "x <= y".
RecordDecl * getDecl() const
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Scope - A scope is a transient data structure that is used while parsing the program.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
CXXTemporary * getTemporary()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
std::pair< CharUnits, CharUnits > getTypeInfoInChars(const Type *T) const
A default argument (C++ [dcl.fct.default]).
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
Checking the operand of a load. Must be suitably sized and aligned.
field_iterator field_end() const
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource AlignSource=AlignmentSource::Type)
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
static CharUnits One()
One - Construct a CharUnits quantity of one.
CastKind
CastKind - The kind of operation required for a conversion.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
const Expr * getExpr() const
Get the initialization expression that will be used.
Represents a call to the builtin function __builtin_va_arg.
std::pair< CharUnits, CharUnits > getTypeInfoDataSizeInChars(QualType T) const
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
llvm::Value * getPointer() const
Expr - This represents one expression.
bool isAnyComplexType() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
bool isAtomicType() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
An RAII object to record that we're evaluating a statement expression.
Expr * getSubExpr() const
An expression that sends a message to the given Objective-C object or class.
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
The scope of a CXXDefaultInitExpr.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
forAddr - Make a slot for an aggregate value.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
InitListExpr * getUpdater() const
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Represents a call to an inherited base class constructor from an inheriting constructor.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
ASTContext & getContext() const
A saved depth on the scope stack.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
A scoped helper to set the current debug location to the specified location or preferred location of ...
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, CodeGenFunction &CGF)
CheckAggExprForMemSetUse - If the initializer is large and has a lot of zeros in it, emit a memset and avoid storing the individual zeros.
const LangOptions & getLangOpts() const
const T * castAs() const
Member-template castAs<specific type>.
bool hasObjectMember() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool hasTrivialCopyAssignment() const
Determine whether this class has a trivial copy assignment operator (C++ [class.copy]p11, C++11 [class.copy]p25)
void setExternallyDestructed(bool destructed=true)
Represents a C11 generic selection.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Expr * getReplacement() const
CharUnits getAlignment() const
Return the alignment of this pointer.
void setVolatile(bool flag)
llvm::Value * getAggregatePointer() const
const Expr * getExpr() const
[C99 6.4.2.2] - A predefined identifier such as func.
Address CreateMemTemp(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignment...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored...
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
U cast(CodeGen::Address addr)
IsAliased_t isPotentiallyAliased() const
bool hasTrivialMoveConstructor() const
Determine whether this class has a trivial move constructor (C++11 [class.copy]p12) ...
Checking the destination of a store. Must be suitably sized and aligned.
detail::InMemoryDirectory::const_iterator E
void EmitAggregateCopy(Address DestPtr, Address SrcPtr, QualType EltTy, bool isVolatile=false, bool isAssignment=false)
EmitAggregateCopy - Emit an aggregate copy.
IsDestructed_t isExternallyDestructed() const
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
static bool hasAggregateEvaluationKind(QualType T)
bool hasTrivialMoveAssignment() const
Determine whether this class has a trivial move assignment operator (C++11 [class.copy]p25)
llvm::PointerType * getType() const
Return the type of the pointer value.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
const T * getAs() const
Member-template getAs<specific type>'.
Expr * getFalseExpr() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
NeedsGCBarriers_t requiresGCollection() const
Address getAddress() const
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
const Expr * getInitializer() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
A use of a default initializer in a constructor or in aggregate initialization.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
const Expr * getSubExpr() const
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
bool isIncompleteArrayType() const
bool isStringLiteralInit() const
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
QualType getElementType() const
const Expr * getInit(unsigned Init) const
const Expr * getSubExpr() const
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
static RValue getAggregate(Address addr, bool isVolatile=false)
CodeGenTypes & getTypes() const
LValue - This represents an lvalue references.
Qualifiers getQualifiers() const
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...
Represents the canonical version of C arrays with a specified constant size.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Represents an implicitly-generated value initialization of an object of a given type.
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.