25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Function.h"
28 #include "llvm/IR/GlobalVariable.h"
29 using namespace clang;
30 using namespace CodeGen;
37 class ConstExprEmitter;
38 class ConstStructBuilder {
48 ConstExprEmitter *Emitter,
49 llvm::ConstantStruct *
Base,
58 : CGM(CGM), CGF(CGF), Packed(
false),
59 NextFieldOffsetInChars(
CharUnits::Zero()),
62 void AppendField(
const FieldDecl *Field, uint64_t FieldOffset,
63 llvm::Constant *InitExpr);
65 void AppendBytes(
CharUnits FieldOffsetInChars, llvm::Constant *InitCst);
67 void AppendBitField(
const FieldDecl *Field, uint64_t FieldOffset,
68 llvm::ConstantInt *InitExpr);
72 void AppendTailPadding(
CharUnits RecordSize);
74 void ConvertStructToPacked();
77 bool Build(ConstExprEmitter *Emitter, llvm::ConstantStruct *
Base,
81 llvm::Constant *Finalize(
QualType Ty);
83 CharUnits getAlignment(
const llvm::Constant *C)
const {
86 CGM.getDataLayout().getABITypeAlignment(C->getType()));
89 CharUnits getSizeInChars(
const llvm::Constant *C)
const {
91 CGM.getDataLayout().getTypeAllocSize(C->getType()));
95 void ConstStructBuilder::
96 AppendField(
const FieldDecl *Field, uint64_t FieldOffset,
97 llvm::Constant *InitCst) {
102 AppendBytes(FieldOffsetInChars, InitCst);
105 void ConstStructBuilder::
106 AppendBytes(
CharUnits FieldOffsetInChars, llvm::Constant *InitCst) {
108 assert(NextFieldOffsetInChars <= FieldOffsetInChars
109 &&
"Field offset mismatch!");
111 CharUnits FieldAlignment = getAlignment(InitCst);
114 CharUnits AlignedNextFieldOffsetInChars =
115 NextFieldOffsetInChars.
alignTo(FieldAlignment);
117 if (AlignedNextFieldOffsetInChars < FieldOffsetInChars) {
119 AppendPadding(FieldOffsetInChars - NextFieldOffsetInChars);
121 assert(NextFieldOffsetInChars == FieldOffsetInChars &&
122 "Did not add enough padding!");
124 AlignedNextFieldOffsetInChars =
125 NextFieldOffsetInChars.
alignTo(FieldAlignment);
128 if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) {
129 assert(!Packed &&
"Alignment is wrong even with a packed struct!");
132 ConvertStructToPacked();
135 if (NextFieldOffsetInChars < FieldOffsetInChars) {
137 AppendPadding(FieldOffsetInChars - NextFieldOffsetInChars);
139 assert(NextFieldOffsetInChars == FieldOffsetInChars &&
140 "Did not add enough padding!");
142 AlignedNextFieldOffsetInChars = NextFieldOffsetInChars;
146 Elements.push_back(InitCst);
147 NextFieldOffsetInChars = AlignedNextFieldOffsetInChars +
148 getSizeInChars(InitCst);
152 "Packed struct not byte-aligned!");
154 LLVMStructAlignment =
std::max(LLVMStructAlignment, FieldAlignment);
157 void ConstStructBuilder::AppendBitField(
const FieldDecl *Field,
158 uint64_t FieldOffset,
159 llvm::ConstantInt *CI) {
162 uint64_t NextFieldOffsetInBits = Context.
toBits(NextFieldOffsetInChars);
163 if (FieldOffset > NextFieldOffsetInBits) {
166 llvm::alignTo(FieldOffset - NextFieldOffsetInBits,
169 AppendPadding(PadSize);
174 llvm::APInt FieldValue = CI->getValue();
180 if (FieldSize > FieldValue.getBitWidth())
181 FieldValue = FieldValue.zext(FieldSize);
184 if (FieldSize < FieldValue.getBitWidth())
185 FieldValue = FieldValue.trunc(FieldSize);
187 NextFieldOffsetInBits = Context.
toBits(NextFieldOffsetInChars);
188 if (FieldOffset < NextFieldOffsetInBits) {
191 assert(!Elements.empty() &&
"Elements can't be empty!");
193 unsigned BitsInPreviousByte = NextFieldOffsetInBits - FieldOffset;
195 bool FitsCompletelyInPreviousByte =
196 BitsInPreviousByte >= FieldValue.getBitWidth();
198 llvm::APInt Tmp = FieldValue;
200 if (!FitsCompletelyInPreviousByte) {
201 unsigned NewFieldWidth = FieldSize - BitsInPreviousByte;
203 if (CGM.getDataLayout().isBigEndian()) {
204 Tmp.lshrInPlace(NewFieldWidth);
205 Tmp = Tmp.trunc(BitsInPreviousByte);
208 FieldValue = FieldValue.trunc(NewFieldWidth);
210 Tmp = Tmp.trunc(BitsInPreviousByte);
213 FieldValue.lshrInPlace(BitsInPreviousByte);
214 FieldValue = FieldValue.trunc(NewFieldWidth);
218 Tmp = Tmp.zext(CharWidth);
219 if (CGM.getDataLayout().isBigEndian()) {
220 if (FitsCompletelyInPreviousByte)
221 Tmp = Tmp.shl(BitsInPreviousByte - FieldValue.getBitWidth());
223 Tmp = Tmp.shl(CharWidth - BitsInPreviousByte);
228 if (llvm::ConstantInt *Val = dyn_cast<llvm::ConstantInt>(LastElt))
229 Tmp |= Val->getValue();
231 assert(isa<llvm::UndefValue>(LastElt));
236 if (!isa<llvm::IntegerType>(LastElt->getType())) {
239 assert(isa<llvm::ArrayType>(LastElt->getType()) &&
240 "Expected array padding of undefs");
241 llvm::ArrayType *AT = cast<llvm::ArrayType>(LastElt->getType());
242 assert(AT->getElementType()->isIntegerTy(CharWidth) &&
243 AT->getNumElements() != 0 &&
244 "Expected non-empty array padding of undefs");
253 assert(isa<llvm::UndefValue>(Elements.back()) &&
254 Elements.back()->getType()->isIntegerTy(CharWidth) &&
255 "Padding addition didn't work right");
259 Elements.back() = llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp);
261 if (FitsCompletelyInPreviousByte)
265 while (FieldValue.getBitWidth() > CharWidth) {
268 if (CGM.getDataLayout().isBigEndian()) {
271 FieldValue.lshr(FieldValue.getBitWidth() - CharWidth).
trunc(CharWidth);
274 Tmp = FieldValue.trunc(CharWidth);
276 FieldValue.lshrInPlace(CharWidth);
279 Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp));
280 ++NextFieldOffsetInChars;
282 FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - CharWidth);
285 assert(FieldValue.getBitWidth() > 0 &&
286 "Should have at least one bit left!");
287 assert(FieldValue.getBitWidth() <= CharWidth &&
288 "Should not have more than a byte left!");
290 if (FieldValue.getBitWidth() < CharWidth) {
291 if (CGM.getDataLayout().isBigEndian()) {
292 unsigned BitWidth = FieldValue.getBitWidth();
294 FieldValue = FieldValue.zext(CharWidth) << (CharWidth - BitWidth);
296 FieldValue = FieldValue.zext(CharWidth);
300 Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(),
302 ++NextFieldOffsetInChars;
305 void ConstStructBuilder::AppendPadding(
CharUnits PadSize) {
311 Ty = llvm::ArrayType::get(Ty, PadSize.
getQuantity());
313 llvm::Constant *C = llvm::UndefValue::get(Ty);
314 Elements.push_back(C);
316 "Padding must have 1 byte alignment!");
318 NextFieldOffsetInChars += getSizeInChars(C);
321 void ConstStructBuilder::AppendTailPadding(
CharUnits RecordSize) {
322 assert(NextFieldOffsetInChars <= RecordSize &&
325 AppendPadding(RecordSize - NextFieldOffsetInChars);
328 void ConstStructBuilder::ConvertStructToPacked() {
332 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
333 llvm::Constant *C = Elements[i];
336 CGM.getDataLayout().getABITypeAlignment(C->getType()));
338 ElementOffsetInChars.
alignTo(ElementAlign);
340 if (AlignedElementOffsetInChars > ElementOffsetInChars) {
343 AlignedElementOffsetInChars - ElementOffsetInChars;
347 Ty = llvm::ArrayType::get(Ty, NumChars.
getQuantity());
349 llvm::Constant *Padding = llvm::UndefValue::get(Ty);
350 PackedElements.push_back(Padding);
351 ElementOffsetInChars += getSizeInChars(Padding);
354 PackedElements.push_back(C);
355 ElementOffsetInChars += getSizeInChars(C);
358 assert(ElementOffsetInChars == NextFieldOffsetInChars &&
359 "Packing the struct changed its size!");
361 Elements.swap(PackedElements);
368 const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
370 unsigned FieldNo = 0;
371 unsigned ElementNo = 0;
376 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
377 if (CXXRD->getNumBases())
381 FieldEnd = RD->
field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
392 llvm::Constant *EltInit;
393 if (ElementNo < ILE->getNumInits())
394 EltInit = CGM.EmitConstantExpr(ILE->
getInit(ElementNo++),
397 EltInit = CGM.EmitNullConstant(Field->
getType());
407 if (
auto *CI = dyn_cast<llvm::ConstantInt>(EltInit)) {
423 : Decl(Decl), Offset(Offset), Index(Index) {
438 const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
442 if (CD->isDynamicClass() && !IsPrimaryBase) {
443 llvm::Constant *VTableAddressPoint =
444 CGM.getCXXABI().getVTableAddressPointForConstExpr(
446 AppendBytes(Offset, VTableAddressPoint);
452 Bases.reserve(CD->getNumBases());
455 BaseEnd = CD->bases_end();
Base != BaseEnd; ++
Base, ++BaseNo) {
456 assert(!
Base->isVirtual() &&
"should not have virtual bases here");
459 Bases.push_back(BaseInfo(BD, BaseOffset, BaseNo));
461 std::stable_sort(Bases.begin(), Bases.end());
463 for (
unsigned I = 0, N = Bases.size();
I != N; ++
I) {
464 BaseInfo &
Base = Bases[
I];
467 Build(Val.
getStructBase(Base.Index), Base.Decl, IsPrimaryBase,
468 VTableClass, Offset + Base.Offset);
472 unsigned FieldNo = 0;
473 uint64_t OffsetBits = CGM.getContext().toBits(Offset);
476 FieldEnd = RD->
field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
488 llvm::Constant *EltInit =
489 CGM.EmitConstantValueForMemory(FieldValue, Field->
getType(), CGF);
490 assert(EltInit &&
"EmitConstantValue can't fail");
494 AppendField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits, EltInit);
497 AppendBitField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits,
498 cast<llvm::ConstantInt>(EltInit));
503 llvm::Constant *ConstStructBuilder::Finalize(
QualType Ty) {
505 const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
509 if (NextFieldOffsetInChars > LayoutSizeInChars) {
513 "Must have flexible array member if struct is bigger than type!");
519 NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
521 if (LLVMSizeInChars != LayoutSizeInChars)
522 AppendTailPadding(LayoutSizeInChars);
524 LLVMSizeInChars = NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
527 if (NextFieldOffsetInChars <= LayoutSizeInChars &&
528 LLVMSizeInChars > LayoutSizeInChars) {
529 assert(!Packed &&
"Size mismatch!");
531 ConvertStructToPacked();
532 assert(NextFieldOffsetInChars <= LayoutSizeInChars &&
533 "Converting to packed did not help!");
536 LLVMSizeInChars = NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
538 assert(LayoutSizeInChars == LLVMSizeInChars &&
539 "Tail padding mismatch!");
544 llvm::StructType *STy =
545 llvm::ConstantStruct::getTypeForElements(CGM.getLLVMContext(),
547 llvm::Type *ValTy = CGM.getTypes().ConvertType(Ty);
548 if (llvm::StructType *ValSTy = dyn_cast<llvm::StructType>(ValTy)) {
549 if (ValSTy->isLayoutIdentical(STy))
553 llvm::Constant *
Result = llvm::ConstantStruct::get(STy, Elements);
555 assert(NextFieldOffsetInChars.alignTo(getAlignment(Result)) ==
556 getSizeInChars(Result) &&
562 llvm::Constant *ConstStructBuilder::BuildStruct(
CodeGenModule &CGM,
564 ConstExprEmitter *Emitter,
565 llvm::ConstantStruct *Base,
567 ConstStructBuilder
Builder(CGM, CGF);
568 if (!
Builder.Build(Emitter, Base, Updater))
573 llvm::Constant *ConstStructBuilder::BuildStruct(
CodeGenModule &CGM,
576 ConstStructBuilder
Builder(CGM, CGF);
584 llvm::Constant *ConstStructBuilder::BuildStruct(
CodeGenModule &CGM,
588 ConstStructBuilder
Builder(CGM, CGF);
594 return Builder.Finalize(ValTy);
606 class ConstExprEmitter :
607 public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
610 llvm::LLVMContext &VMContext;
613 : CGM(cgm), CGF(cgf), VMContext(cgm.getLLVMContext()) {
620 llvm::Constant *VisitStmt(
Stmt *
S) {
624 llvm::Constant *VisitParenExpr(
ParenExpr *PE) {
637 llvm::Constant *VisitChooseExpr(
ChooseExpr *CE) {
645 llvm::Constant *VisitCastExpr(
CastExpr* E) {
646 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
650 if (!C)
return nullptr;
658 "Destination type is not union type!");
665 Types.push_back(C->getType());
666 unsigned CurSize = CGM.
getDataLayout().getTypeAllocSize(C->getType());
667 unsigned TotalSize = CGM.
getDataLayout().getTypeAllocSize(destType);
669 assert(CurSize <= TotalSize &&
"Union size mismatch!");
670 if (
unsigned NumPadBytes = TotalSize - CurSize) {
673 Ty = llvm::ArrayType::get(Ty, NumPadBytes);
675 Elts.push_back(llvm::UndefValue::get(Ty));
679 llvm::StructType* STy =
680 llvm::StructType::get(C->getType()->getContext(), Types,
false);
681 return llvm::ConstantStruct::get(STy, Elts);
684 case CK_AddressSpaceConversion:
685 return llvm::ConstantExpr::getAddrSpaceCast(C, destType);
687 case CK_LValueToRValue:
688 case CK_AtomicToNonAtomic:
689 case CK_NonAtomicToAtomic:
691 case CK_ConstructorConversion:
694 case CK_IntToOCLSampler:
695 llvm_unreachable(
"global sampler variables are not generated");
697 case CK_Dependent: llvm_unreachable(
"saw dependent cast!");
699 case CK_BuiltinFnToFnPtr:
700 llvm_unreachable(
"builtin functions are handled elsewhere");
702 case CK_ReinterpretMemberPointer:
703 case CK_DerivedToBaseMemberPointer:
704 case CK_BaseToDerivedMemberPointer:
708 case CK_ObjCObjectLValueCast:
709 case CK_ARCProduceObject:
710 case CK_ARCConsumeObject:
711 case CK_ARCReclaimReturnedObject:
712 case CK_ARCExtendBlockObject:
713 case CK_CopyAndAutoreleaseBlockObject:
721 case CK_LValueBitCast:
722 case CK_NullToMemberPointer:
723 case CK_UserDefinedConversion:
724 case CK_CPointerToObjCPointerCast:
725 case CK_BlockPointerToObjCPointerCast:
726 case CK_AnyPointerToBlockPointerCast:
727 case CK_ArrayToPointerDecay:
728 case CK_FunctionToPointerDecay:
729 case CK_BaseToDerived:
730 case CK_DerivedToBase:
731 case CK_UncheckedDerivedToBase:
732 case CK_MemberPointerToBoolean:
734 case CK_FloatingRealToComplex:
735 case CK_FloatingComplexToReal:
736 case CK_FloatingComplexToBoolean:
737 case CK_FloatingComplexCast:
738 case CK_FloatingComplexToIntegralComplex:
739 case CK_IntegralRealToComplex:
740 case CK_IntegralComplexToReal:
741 case CK_IntegralComplexToBoolean:
742 case CK_IntegralComplexCast:
743 case CK_IntegralComplexToFloatingComplex:
744 case CK_PointerToIntegral:
745 case CK_PointerToBoolean:
746 case CK_NullToPointer:
747 case CK_IntegralCast:
748 case CK_BooleanToSignedIntegral:
749 case CK_IntegralToPointer:
750 case CK_IntegralToBoolean:
751 case CK_IntegralToFloating:
752 case CK_FloatingToIntegral:
753 case CK_FloatingToBoolean:
754 case CK_FloatingCast:
755 case CK_ZeroToOCLEvent:
756 case CK_ZeroToOCLQueue:
759 llvm_unreachable(
"Invalid CastKind");
782 llvm::Constant *EmitArrayInitialization(
InitListExpr *ILE) {
783 llvm::ArrayType *AType =
784 cast<llvm::ArrayType>(ConvertType(ILE->
getType()));
787 unsigned NumElements = AType->getNumElements();
791 unsigned NumInitableElts =
std::min(NumInitElements, NumElements);
795 llvm::Constant *fillC;
799 fillC = llvm::Constant::getNullValue(ElemTy);
804 if (fillC->isNullValue() && !NumInitableElts)
805 return llvm::ConstantAggregateZero::get(AType);
808 std::vector<llvm::Constant*> Elts;
809 Elts.reserve(NumInitableElts + NumElements);
811 bool RewriteType =
false;
812 for (
unsigned i = 0; i < NumInitableElts; ++i) {
817 RewriteType |= (C->getType() != ElemTy);
821 RewriteType |= (fillC->getType() != ElemTy);
822 Elts.resize(NumElements, fillC);
826 std::vector<llvm::Type*> Types;
827 Types.reserve(NumInitableElts + NumElements);
828 for (
unsigned i = 0, e = Elts.size(); i < e; ++i)
829 Types.push_back(Elts[i]->getType());
830 llvm::StructType *SType = llvm::StructType::get(AType->getContext(),
832 return llvm::ConstantStruct::get(SType, Elts);
835 return llvm::ConstantArray::get(AType, Elts);
838 llvm::Constant *EmitRecordInitialization(
InitListExpr *ILE) {
839 return ConstStructBuilder::BuildStruct(CGM, CGF, ILE);
851 return EmitArrayInitialization(ILE);
854 return EmitRecordInitialization(ILE);
859 llvm::Constant *EmitDesignatedInitUpdater(llvm::Constant *Base,
864 llvm::ArrayType *AType = cast<llvm::ArrayType>(ConvertType(ExprType));
865 llvm::Type *ElemType = AType->getElementType();
868 unsigned NumElements = AType->getNumElements();
870 std::vector<llvm::Constant *> Elts;
871 Elts.reserve(NumElements);
873 if (llvm::ConstantDataArray *DataArray =
874 dyn_cast<llvm::ConstantDataArray>(Base))
875 for (
unsigned i = 0; i != NumElements; ++i)
876 Elts.push_back(DataArray->getElementAsConstant(i));
877 else if (llvm::ConstantArray *Array =
878 dyn_cast<llvm::ConstantArray>(Base))
879 for (
unsigned i = 0; i != NumElements; ++i)
880 Elts.push_back(Array->getOperand(i));
884 llvm::Constant *fillC =
nullptr;
886 if (!isa<NoInitExpr>(filler))
888 bool RewriteType = (fillC && fillC->getType() != ElemType);
890 for (
unsigned i = 0; i != NumElements; ++i) {
891 Expr *Init =
nullptr;
892 if (i < NumInitElements)
897 else if (!Init || isa<NoInitExpr>(Init))
899 else if (
InitListExpr *ChildILE = dyn_cast<InitListExpr>(Init))
900 Elts[i] = EmitDesignatedInitUpdater(Elts[i], ChildILE);
906 RewriteType |= (Elts[i]->getType() != ElemType);
910 std::vector<llvm::Type *> Types;
911 Types.reserve(NumElements);
912 for (
unsigned i = 0; i != NumElements; ++i)
913 Types.push_back(Elts[i]->getType());
914 llvm::StructType *SType = llvm::StructType::get(AType->getContext(),
916 return llvm::ConstantStruct::get(SType, Elts);
919 return llvm::ConstantArray::get(AType, Elts);
923 return ConstStructBuilder::BuildStruct(CGM, CGF,
this,
924 dyn_cast<llvm::ConstantStruct>(Base), Updater);
930 return EmitDesignatedInitUpdater(
948 if (!RD->hasTrivialDestructor())
955 assert(E->
getNumArgs() == 1 &&
"trivial ctor with > 1 argument");
957 "trivial ctor has argument but isn't a copy/move ctor");
961 "argument to copy ctor is of wrong type");
981 T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
986 Str.resize(CAT->
getSize().getZExtValue(),
'\0');
987 return llvm::ConstantDataArray::getString(VMContext, Str,
false);
990 llvm::Constant *VisitUnaryExtension(
const UnaryOperator *E) {
1006 if (
const VarDecl* VD = dyn_cast<VarDecl>(
Decl)) {
1008 if (!VD->hasLocalStorage()) {
1010 if (VD->isFileVarDecl() || VD->hasExternalStorage())
1012 else if (VD->isLocalVarDecl()) {
1022 Expr *E =
const_cast<Expr*
>(LVBase.get<
const Expr*>());
1025 case Expr::CompoundLiteralExprClass: {
1028 if (llvm::GlobalVariable *Addr =
1037 auto GV =
new llvm::GlobalVariable(CGM.
getModule(), C->getType(),
1040 C,
".compoundliteral",
nullptr,
1041 llvm::GlobalVariable::NotThreadLocal,
1043 GV->setAlignment(Align.getQuantity());
1047 case Expr::StringLiteralClass:
1049 case Expr::ObjCEncodeExprClass:
1051 case Expr::ObjCStringLiteralClass: {
1057 case Expr::PredefinedExprClass: {
1058 unsigned Type = cast<PredefinedExpr>(
E)->getIdentType();
1061 return cast<ConstantAddress>(Res.
getAddress());
1068 case Expr::AddrLabelExprClass: {
1069 assert(CGF &&
"Invalid address of label expression outside function.");
1070 llvm::Constant *Ptr =
1072 Ptr = llvm::ConstantExpr::getBitCast(Ptr, ConvertType(E->
getType()));
1075 case Expr::CallExprClass: {
1079 Builtin::BI__builtin___CFStringMakeConstantString &&
1081 Builtin::BI__builtin___NSStringMakeConstantString)
1086 Builtin::BI__builtin___NSStringMakeConstantString) {
1092 case Expr::BlockExprClass: {
1093 StringRef FunctionName;
1095 FunctionName = CGF->
CurFn->getName();
1097 FunctionName =
"global";
1100 llvm::Constant *Ptr =
1104 case Expr::CXXTypeidExprClass: {
1114 case Expr::CXXUuidofExprClass: {
1117 case Expr::MaterializeTemporaryExprClass: {
1134 bool ConstStructBuilder::Build(ConstExprEmitter *Emitter,
1135 llvm::ConstantStruct *Base,
1137 assert(Base &&
"base expression should not be empty");
1142 const llvm::StructLayout *BaseLayout = CGM.
getDataLayout().getStructLayout(
1144 unsigned FieldNo = -1;
1145 unsigned ElementNo = 0;
1150 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1151 if (CXXRD->getNumBases())
1164 llvm::Constant *EltInit = Base->getOperand(ElementNo);
1170 BaseLayout->getElementOffsetInBits(ElementNo))
1175 Expr *Init =
nullptr;
1176 if (ElementNo < Updater->getNumInits())
1177 Init = Updater->
getInit(ElementNo);
1179 if (!Init || isa<NoInitExpr>(Init))
1181 else if (
InitListExpr *ChildILE = dyn_cast<InitListExpr>(Init))
1182 EltInit = Emitter->EmitDesignatedInitUpdater(EltInit, ChildILE);
1193 else if (llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(EltInit))
1214 dyn_cast_or_null<CXXConstructExpr>(D.
getInit())) {
1234 assert(E &&
"No initializer to emit");
1236 llvm::Constant* C = ConstExprEmitter(*
this, CGF).Visit(const_cast<Expr*>(E));
1237 if (C && C->getType()->isIntegerTy(1)) {
1239 C = llvm::ConstantExpr::getZExt(C, BoolTy);
1249 bool Success =
false;
1256 llvm::Constant *C =
nullptr;
1260 C = ConstExprEmitter(*
this, CGF).Visit(const_cast<Expr*>(E));
1262 if (C && C->getType()->isIntegerTy(1)) {
1264 C = llvm::ConstantExpr::getZExt(C, BoolTy);
1278 QualType InnerType = AT->getValueType();
1281 uint64_t InnerSize = Context.
getTypeSize(InnerType);
1282 uint64_t OuterSize = Context.
getTypeSize(DestType);
1283 if (InnerSize == OuterSize)
1286 assert(InnerSize < OuterSize &&
"emitted over-large constant for atomic");
1287 llvm::Constant *Elts[] = {
1289 llvm::ConstantAggregateZero::get(
1290 llvm::ArrayType::get(
Int8Ty, (OuterSize - InnerSize) / 8))
1292 return llvm::ConstantStruct::getAnon(Elts);
1297 llvm_unreachable(
"Constant expressions should be initialized.");
1300 llvm::Constant *Offset =
1303 llvm::Constant *C =
nullptr;
1307 if (isa<llvm::ArrayType>(DestTy)) {
1308 assert(Offset->isNullValue() &&
"offset on array initializer");
1309 return ConstExprEmitter(*
this, CGF).Visit(
1310 const_cast<Expr*>(LVBase.get<
const Expr*>()));
1313 C = ConstExprEmitter(*
this, CGF).EmitLValue(LVBase).getPointer();
1316 if (!Offset->isNullValue()) {
1317 unsigned AS = C->getType()->getPointerAddressSpace();
1319 llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, CharPtrTy);
1320 Casted = llvm::ConstantExpr::getGetElementPtr(
Int8Ty, Casted, Offset);
1321 C = llvm::ConstantExpr::getPointerCast(Casted, C->getType());
1326 if (isa<llvm::PointerType>(DestTy))
1327 return llvm::ConstantExpr::getPointerCast(C, DestTy);
1329 return llvm::ConstantExpr::getPtrToInt(C, DestTy);
1335 if (
auto PT = dyn_cast<llvm::PointerType>(DestTy)) {
1340 C = llvm::ConstantExpr::getIntegerCast(
1343 return llvm::ConstantExpr::getIntToPtr(C, DestTy);
1347 if (C->getType() != DestTy)
1348 return llvm::ConstantExpr::getTrunc(C, DestTy);
1354 return llvm::ConstantInt::get(VMContext, Value.
getInt());
1356 llvm::Constant *Complex[2];
1358 Complex[0] = llvm::ConstantInt::get(VMContext,
1360 Complex[1] = llvm::ConstantInt::get(VMContext,
1364 llvm::StructType *STy =
1365 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
1366 return llvm::ConstantStruct::get(STy, Complex);
1369 const llvm::APFloat &Init = Value.
getFloat();
1370 if (&Init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
1373 return llvm::ConstantInt::get(VMContext, Init.bitcastToAPInt());
1375 return llvm::ConstantFP::get(VMContext, Init);
1378 llvm::Constant *Complex[2];
1380 Complex[0] = llvm::ConstantFP::get(VMContext,
1382 Complex[1] = llvm::ConstantFP::get(VMContext,
1386 llvm::StructType *STy =
1387 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
1388 return llvm::ConstantStruct::get(STy, Complex);
1394 for (
unsigned I = 0;
I != NumElts; ++
I) {
1397 Inits[
I] = llvm::ConstantInt::get(VMContext, Elt.
getInt());
1399 Inits[
I] = llvm::ConstantFP::get(VMContext, Elt.
getFloat());
1401 llvm_unreachable(
"unsupported vector element type");
1403 return llvm::ConstantVector::get(Inits);
1413 LHS = llvm::ConstantExpr::getPtrToInt(LHS,
IntPtrTy);
1414 RHS = llvm::ConstantExpr::getPtrToInt(RHS,
IntPtrTy);
1415 llvm::Constant *AddrLabelDiff = llvm::ConstantExpr::getSub(LHS, RHS);
1420 return llvm::ConstantExpr::getTruncOrBitCast(AddrLabelDiff, ResultType);
1424 return ConstStructBuilder::BuildStruct(*
this, CGF, Value, DestType);
1431 llvm::Constant *Filler =
nullptr;
1441 if (Filler && Filler->isNullValue() && !NumInitElts) {
1442 llvm::ArrayType *AType =
1443 llvm::ArrayType::get(CommonElementType, NumElements);
1444 return llvm::ConstantAggregateZero::get(AType);
1447 std::vector<llvm::Constant*> Elts;
1448 Elts.reserve(NumElements);
1449 for (
unsigned I = 0;
I < NumElements; ++
I) {
1450 llvm::Constant *C = Filler;
1451 if (
I < NumInitElts)
1455 assert(Filler &&
"Missing filler for implicit elements of initializer");
1457 CommonElementType = C->getType();
1458 else if (C->getType() != CommonElementType)
1459 CommonElementType =
nullptr;
1463 if (!CommonElementType) {
1465 std::vector<llvm::Type*> Types;
1466 Types.reserve(NumElements);
1467 for (
unsigned i = 0, e = Elts.size(); i < e; ++i)
1468 Types.push_back(Elts[i]->getType());
1469 llvm::StructType *SType = llvm::StructType::get(VMContext, Types,
true);
1470 return llvm::ConstantStruct::get(SType, Elts);
1473 llvm::ArrayType *AType =
1474 llvm::ArrayType::get(CommonElementType, NumElements);
1475 return llvm::ConstantArray::get(AType, Elts);
1480 llvm_unreachable(
"Unknown APValue kind");
1488 if (C->getType()->isIntegerTy(1)) {
1490 C = llvm::ConstantExpr::getZExt(C, BoolTy);
1497 return EmittedCompoundLiterals.lookup(E);
1502 bool Ok = EmittedCompoundLiterals.insert(std::make_pair(CLE, GV)).second;
1504 assert(Ok &&
"CLE has already been emitted!");
1509 assert(E->
isFileScope() &&
"not a file-scope compound literal expr");
1510 return ConstExprEmitter(*
this,
nullptr).EmitLValue(E);
1520 if (
const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(decl))
1535 bool asCompleteObject) {
1537 llvm::StructType *structure =
1541 unsigned numElements = structure->getNumElements();
1542 std::vector<llvm::Constant *> elements(numElements);
1547 for (
const auto &
I : CXXR->bases()) {
1548 if (
I.isVirtual()) {
1555 cast<CXXRecordDecl>(
I.getType()->castAs<
RecordType>()->getDecl());
1564 llvm::Type *baseType = structure->getElementType(fieldIndex);
1570 for (
const auto *Field : record->
fields()) {
1582 if (
const auto *FieldRD =
1584 if (FieldRD->findFirstNamedDataMember())
1590 if (CXXR && asCompleteObject) {
1591 for (
const auto &
I : CXXR->vbases()) {
1593 cast<CXXRecordDecl>(
I.getType()->castAs<
RecordType>()->getDecl());
1602 if (elements[fieldIndex])
continue;
1604 llvm::Type *baseType = structure->getElementType(fieldIndex);
1610 for (
unsigned i = 0; i != numElements; ++i) {
1612 elements[i] = llvm::Constant::getNullValue(structure->getElementType(i));
1615 return llvm::ConstantStruct::get(structure, elements);
1626 return llvm::Constant::getNullValue(baseType);
1635 cast<llvm::PointerType>(
getTypes().ConvertTypeForMem(T)), T);
1637 if (
getTypes().isZeroInitializable(T))
1638 return llvm::Constant::getNullValue(
getTypes().ConvertTypeForMem(T));
1641 llvm::ArrayType *ATy =
1647 unsigned NumElements = CAT->
getSize().getZExtValue();
1649 return llvm::ConstantArray::get(ATy, Array);
1656 "Should only see pointers to data members here!");
Defines the clang::ASTContext interface.
unsigned getNumInits() const
StmtClass getStmtClass() const
CastKind getCastKind() const
virtual llvm::Constant * EmitMemberPointer(const APValue &MP, QualType MPT)
Create a member pointer for the given member pointer constant.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
const FieldDecl * getUnionField() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
A (possibly-)qualified type.
CodeGenTypes & getTypes()
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
bool isBitField() const
Determines whether this field is a bitfield.
llvm::Module & getModule() const
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
llvm::Constant * getMemberPointerConstant(const UnaryOperator *e)
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
Stmt - This represents one statement.
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
Decl - This represents one declaration (or definition), e.g.
Address getAddress() const
bool hasFlexibleArrayMember() const
ParenExpr - This represents a parethesized expression, e.g.
const llvm::DataLayout & getDataLayout() const
The base class of the type hierarchy.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
const Expr * getResultExpr() const
The generic selection's result expression.
const Expr * getInit() const
Represents a call to a C++ constructor.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
llvm::Constant * EmitConstantValue(const APValue &Value, QualType DestType, CodeGenFunction *CGF=nullptr)
Emit the given constant value as a constant, in the type's scalar representation. ...
const llvm::APInt & getSize() const
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
llvm::StructType * getLLVMType() const
Return the "complete object" LLVM type associated with this record.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
CompoundLiteralExpr - [C99 6.5.2.5].
APFloat & getComplexFloatReal()
field_iterator field_begin() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
bool isMemberDataPointerType() const
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
llvm::Constant * EmitConstantValueForMemory(const APValue &Value, QualType DestType, CodeGenFunction *CGF=nullptr)
Emit the given constant value as a constant, in the type's memory representation. ...
RecordDecl - Represents a struct/union/class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
bool isNullPointer() const
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::IntegerType * Int64Ty
bool isReferenceType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
StringLiteral * getString()
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
unsigned getVirtualBaseIndex(const CXXRecordDecl *base) const
Return the LLVM field index corresponding to the given virtual base.
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.
const TargetInfo & getTargetInfo() const
const LangOptions & getLangOpts() const
CharUnits - This is an opaque type for sizes expressed in character units.
APValue Val
Val - This is the value the expression can be folded to.
bool isZeroInitializableAsBase() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer when considered as a bas...
Expr * getExprOperand() const
field_range fields() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
RecordDecl * getDecl() const
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
ObjCStringLiteral, used for Objective-C string literals i.e.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
TypeClass getTypeClass() const
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
detail::InMemoryDirectory::const_iterator I
APSInt & getComplexIntReal()
A default argument (C++ [dcl.fct.default]).
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
field_iterator field_end() const
APValue & getVectorElt(unsigned I)
static CharUnits One()
One - Construct a CharUnits quantity of one.
const TargetCodeGenInfo & getTargetCodeGenInfo()
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
APValue & getArrayFiller()
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
const Expr * getExpr() const
Get the initialization expression that will be used.
unsigned getCharAlign() const
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
unsigned getArrayInitializedElts() const
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
CGCXXABI & getCXXABI() const
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
ASTContext & getContext() const
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
Expr * getSubExpr() const
APValue & getStructField(unsigned i)
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
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...
APSInt & getComplexIntImag()
InitListExpr * getUpdater() const
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
The l-value was considered opaque, so the alignment was determined from a type.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
APValue & getStructBase(unsigned i)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
bool cleanupsHaveSideEffects() const
APValue & getArrayInitializedElt(unsigned I)
virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion. ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
llvm::Constant * EmitConstantExpr(const Expr *E, QualType DestType, CodeGenFunction *CGF=nullptr)
Try to emit the given expression as a constant; returns 0 if the expression cannot be emitted as a co...
CharUnits getPointerAlign() const
CharUnits getSize() const
getSize - Get the record size in characters.
virtual ConstantAddress GenerateConstantString(const StringLiteral *)=0
Generate a constant string object.
virtual llvm::Constant * getNullPointer(const CodeGen::CodeGenModule &CGM, llvm::PointerType *T, QualType QT) const
Get target specific null pointer.
bool isConstant(const ASTContext &Ctx) const
unsigned getBitWidthValue(const ASTContext &Ctx) const
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
const AddrLabelExpr * getAddrLabelDiffLHS() const
APValue & getUnionValue()
ValueKind getKind() const
ConstantAddress getElementBitCast(llvm::Type *ty) const
Represents a static or instance method of a struct/union/class.
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
const T * castAs() const
Member-template castAs<specific type>.
const AddrLabelExpr * getAddrLabelDiffRHS() const
llvm::GlobalVariable * getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E)
If it's been emitted already, returns the GlobalVariable corresponding to a compound literal...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)
Create a null member pointer of the given type.
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character...
Represents a C11 generic selection.
AddrLabelExpr - The GNU address of label extension, representing &&label.
Expr * getReplacement() const
This class organizes the cross-function state that is used while generating LLVM code.
const Expr * getExpr() const
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
EvalResult is a struct with detailed info about an evaluated expression.
bool isZero() const
isZero - Test whether the quantity equals zero.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const
static llvm::Constant * EmitNullConstantForBase(CodeGenModule &CGM, llvm::Type *baseType, const CXXRecordDecl *base)
Emit the null constant for a base subobject.
llvm::IntegerType * IntPtrTy
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
unsigned getNumArgs() 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 EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
bool HasSideEffects
Whether the evaluated expression has side effects.
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>'.
llvm::PointerUnion< const ValueDecl *, const Expr * > LValueBase
ObjCEncodeExpr, used for @encode in Objective-C.
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression...
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
const Expr * getInitializer() const
llvm::Constant * EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF=nullptr)
Try to emit the initializer for the given declaration as a constant; returns 0 if the expression cann...
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
A use of a default initializer in a constructor or in aggregate initialization.
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, llvm::GlobalVariable *GV)
Notes that CLE's GlobalVariable is GV.
static llvm::Constant * EmitNullConstant(CodeGenModule &CGM, const RecordDecl *record, bool asCompleteObject)
const Expr * getSubExpr() const
APFloat & getComplexFloatImag()
const LValueBase getLValueBase() const
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
QualType getEncodedType() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
A specialization of Address that requires the address to be an LLVM Constant.
LValue EmitPredefinedLValue(const PredefinedExpr *E)
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static ConstantAddress invalid()
unsigned getTargetAddressSpace(QualType T) const
QualType getElementType() const
const Expr * getInit(unsigned Init) const
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
LValue - This represents an lvalue references.
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
unsigned getArraySize() const
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool isTypeOperand() const
llvm::StructType * getBaseSubobjectLLVMType() const
Return the "base subobject" LLVM type associated with this record.
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
Represents the canonical version of C arrays with a specified constant size.
unsigned getVectorLength() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Defines enum values for all the target-independent builtin functions.
Represents an implicitly-generated value initialization of an object of a given type.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
bool hasArrayFiller() const
CharUnits & getLValueOffset()