26 #include "llvm/IR/CFG.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GlobalVariable.h"
31 #include "llvm/IR/Intrinsics.h"
32 #include "llvm/IR/Module.h"
35 using namespace clang;
36 using namespace CodeGen;
53 static bool MustVisitNullValue(
const Expr *
E) {
60 class ScalarExprEmitter
64 bool IgnoreResultAssign;
65 llvm::LLVMContext &VMContext;
70 VMContext(cgf.getLLVMContext()) {
77 bool TestAndClearIgnoreResultAssign() {
78 bool I = IgnoreResultAssign;
79 IgnoreResultAssign =
false;
84 LValue EmitLValue(
const Expr *E) {
return CGF.EmitLValue(E); }
86 return CGF.EmitCheckedLValue(E, TCK);
89 void EmitBinOpCheck(
ArrayRef<std::pair<Value *, SanitizerMask>> Checks,
90 const BinOpInfo &Info);
93 return CGF.EmitLoadOfLValue(LV, Loc).getScalarVal();
96 void EmitLValueAlignmentAssumption(
const Expr *E,
Value *V) {
97 const AlignValueAttr *AVAttr =
nullptr;
98 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
102 if (
const auto *TTy =
104 AVAttr = TTy->getDecl()->
getAttr<AlignValueAttr>();
108 if (isa<ParmVarDecl>(VD))
111 AVAttr = VD->
getAttr<AlignValueAttr>();
116 if (
const auto *TTy =
117 dyn_cast<TypedefType>(E->
getType()))
118 AVAttr = TTy->getDecl()->getAttr<AlignValueAttr>();
123 Value *AlignmentValue = CGF.EmitScalarExpr(AVAttr->getAlignment());
124 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(AlignmentValue);
125 CGF.EmitAlignmentAssumption(V, AlignmentCI->getZExtValue());
135 EmitLValueAlignmentAssumption(E, V);
145 void EmitFloatConversionCheck(
Value *OrigSrc,
QualType OrigSrcType,
169 llvm::Value *Zero = llvm::Constant::getNullValue(V->getType());
170 return Builder.CreateFCmpUNE(V, Zero,
"tobool");
174 Value *EmitPointerToBoolConversion(
Value *V) {
175 Value *Zero = llvm::ConstantPointerNull::get(
176 cast<llvm::PointerType>(V->getType()));
177 return Builder.CreateICmpNE(V, Zero,
"tobool");
184 if (llvm::ZExtInst *ZI = dyn_cast<llvm::ZExtInst>(V)) {
185 if (ZI->getOperand(0)->getType() ==
Builder.getInt1Ty()) {
191 ZI->eraseFromParent();
196 return Builder.CreateIsNotNull(V,
"tobool");
209 S->dump(CGF.getContext().getSourceManager());
210 llvm_unreachable(
"Stmt can't have complex result type!");
229 return llvm::ConstantFP::get(VMContext, E->
getValue());
232 return llvm::ConstantInt::get(ConvertType(E->
getType()), E->
getValue());
235 return llvm::ConstantInt::get(ConvertType(E->
getType()), E->
getValue());
238 return llvm::ConstantInt::get(ConvertType(E->
getType()), E->
getValue());
241 return EmitNullValue(E->
getType());
244 return EmitNullValue(E->
getType());
258 return CGF.EmitPseudoObjectRValue(E).getScalarVal();
263 return EmitLoadOfLValue(CGF.getOpaqueLValueMapping(E), E->
getExprLoc());
266 return CGF.getOpaqueRValueMapping(E).getScalarVal();
272 if (result.isReference())
273 return EmitLoadOfLValue(result.getReferenceLValue(CGF, E),
275 return result.getValue();
277 return EmitLoadOfLValue(E);
281 return CGF.EmitObjCSelectorExpr(E);
284 return CGF.EmitObjCProtocolExpr(E);
287 return EmitLoadOfLValue(E);
292 return EmitLoadOfLValue(E);
293 return CGF.EmitObjCMessageExpr(E).getScalarVal();
297 LValue LV = CGF.EmitObjCIsaExpr(E);
306 Value *VisitExtVectorElementExpr(
Expr *E) {
return EmitLoadOfLValue(E); }
308 return EmitLoadOfLValue(E);
314 return EmitNullValue(E->
getType());
317 CGF.CGM.EmitExplicitCastExprType(E, &CGF);
318 return VisitCastExpr(E);
324 return EmitLoadOfLValue(E);
326 Value *V = CGF.EmitCallExpr(E).getScalarVal();
328 EmitLValueAlignmentAssumption(E, V);
337 return EmitScalarPrePostIncDec(E, LV,
false,
false);
341 return EmitScalarPrePostIncDec(E, LV,
true,
false);
345 return EmitScalarPrePostIncDec(E, LV,
false,
true);
349 return EmitScalarPrePostIncDec(E, LV,
true,
true);
357 bool isInc,
bool isPre);
361 if (isa<MemberPointerType>(E->
getType()))
362 return CGF.CGM.getMemberPointerConstant(E);
364 return EmitLValue(E->
getSubExpr()).getPointer();
369 return EmitLoadOfLValue(E);
373 TestAndClearIgnoreResultAssign();
387 return EmitLoadOfLValue(E);
398 return CGF.LoadCXXThis();
402 CGF.enterFullExpression(E);
407 return CGF.EmitCXXNewExpr(E);
410 CGF.EmitCXXDeleteExpr(E);
415 return llvm::ConstantInt::get(ConvertType(E->
getType()), E->
getValue());
432 CGF.EmitScalarExpr(E->
getBase());
437 return EmitNullValue(E->
getType());
441 CGF.EmitCXXThrowExpr(E);
450 Value *EmitMul(
const BinOpInfo &Ops) {
451 if (Ops.Ty->isSignedIntegerOrEnumerationType()) {
452 switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
454 return Builder.CreateMul(Ops.LHS, Ops.RHS,
"mul");
456 if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
457 return Builder.CreateNSWMul(Ops.LHS, Ops.RHS,
"mul");
460 return EmitOverflowCheckedBinOp(Ops);
464 if (Ops.Ty->isUnsignedIntegerType() &&
465 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow))
466 return EmitOverflowCheckedBinOp(Ops);
468 if (Ops.LHS->getType()->isFPOrFPVectorTy())
469 return Builder.CreateFMul(Ops.LHS, Ops.RHS,
"mul");
470 return Builder.CreateMul(Ops.LHS, Ops.RHS,
"mul");
474 Value *EmitOverflowCheckedBinOp(
const BinOpInfo &Ops);
477 void EmitUndefinedBehaviorIntegerDivAndRemCheck(
const BinOpInfo &Ops,
481 Value *EmitDiv(
const BinOpInfo &Ops);
482 Value *EmitRem(
const BinOpInfo &Ops);
483 Value *EmitAdd(
const BinOpInfo &Ops);
484 Value *EmitSub(
const BinOpInfo &Ops);
485 Value *EmitShl(
const BinOpInfo &Ops);
486 Value *EmitShr(
const BinOpInfo &Ops);
487 Value *EmitAnd(
const BinOpInfo &Ops) {
488 return Builder.CreateAnd(Ops.LHS, Ops.RHS,
"and");
490 Value *EmitXor(
const BinOpInfo &Ops) {
491 return Builder.CreateXor(Ops.LHS, Ops.RHS,
"xor");
493 Value *EmitOr (
const BinOpInfo &Ops) {
494 return Builder.CreateOr(Ops.LHS, Ops.RHS,
"or");
499 Value *(ScalarExprEmitter::*F)(
const BinOpInfo &),
503 Value *(ScalarExprEmitter::*F)(
const BinOpInfo &));
506 #define HANDLEBINOP(OP) \
507 Value *VisitBin ## OP(const BinaryOperator *E) { \
508 return Emit ## OP(EmitBinOps(E)); \
510 Value *VisitBin ## OP ## Assign(const CompoundAssignOperator *E) { \
511 return EmitCompoundAssign(E, &ScalarExprEmitter::Emit ## OP); \
527 llvm::CmpInst::Predicate SICmpOpc,
528 llvm::CmpInst::Predicate FCmpOpc);
529 #define VISITCOMP(CODE, UI, SI, FP) \
530 Value *VisitBin##CODE(const BinaryOperator *E) { \
531 return EmitCompare(E, llvm::ICmpInst::UI, llvm::ICmpInst::SI, \
532 llvm::FCmpInst::FP); }
533 VISITCOMP(LT, ICMP_ULT, ICMP_SLT, FCMP_OLT)
534 VISITCOMP(GT, ICMP_UGT, ICMP_SGT, FCMP_OGT)
535 VISITCOMP(LE, ICMP_ULE, ICMP_SLE, FCMP_OLE)
536 VISITCOMP(GE, ICMP_UGE, ICMP_SGE, FCMP_OGE)
537 VISITCOMP(EQ, ICMP_EQ , ICMP_EQ , FCMP_OEQ)
538 VISITCOMP(NE, ICMP_NE , ICMP_NE , FCMP_UNE)
547 Value *VisitBinPtrMemD(
const Expr *E) {
return EmitLoadOfLValue(E); }
548 Value *VisitBinPtrMemI(
const Expr *E) {
return EmitLoadOfLValue(E); }
556 return CGF.EmitObjCStringLiteral(E);
559 return CGF.EmitObjCBoxedExpr(E);
562 return CGF.EmitObjCArrayLiteral(E);
565 return CGF.EmitObjCDictionaryLiteral(E);
579 assert(SrcType.
isCanonical() &&
"EmitScalarConversion strips typedefs");
582 return EmitFloatToBoolConversion(Src);
585 return CGF.CGM.getCXXABI().EmitMemberPointerIsNotNull(CGF, Src, MPT);
587 assert((SrcType->
isIntegerType() || isa<llvm::PointerType>(Src->getType())) &&
588 "Unknown scalar type to convert");
590 if (isa<llvm::IntegerType>(Src->getType()))
591 return EmitIntToBoolConversion(Src);
593 assert(isa<llvm::PointerType>(Src->getType()));
594 return EmitPointerToBoolConversion(Src);
597 void ScalarExprEmitter::EmitFloatConversionCheck(
607 if (llvm::IntegerType *IntTy = dyn_cast<llvm::IntegerType>(SrcTy)) {
613 APFloat LargestFloat =
614 APFloat::getLargest(CGF.getContext().getFloatTypeSemantics(DstType));
615 APSInt LargestInt(IntTy->getBitWidth(), SrcIsUnsigned);
618 if (LargestFloat.convertToInteger(LargestInt, APFloat::rmTowardZero,
619 &IsExact) != APFloat::opOK)
624 llvm::Value *Max = llvm::ConstantInt::get(VMContext, LargestInt);
626 Check =
Builder.CreateICmpULE(Src, Max);
628 llvm::Value *Min = llvm::ConstantInt::get(VMContext, -LargestInt);
631 Check =
Builder.CreateAnd(GE, LE);
634 const llvm::fltSemantics &SrcSema =
635 CGF.getContext().getFloatTypeSemantics(OrigSrcType);
636 if (isa<llvm::IntegerType>(DstTy)) {
640 unsigned Width = CGF.getContext().getIntWidth(DstType);
643 APSInt Min = APSInt::getMinValue(Width, Unsigned);
644 APFloat MinSrc(SrcSema, APFloat::uninitialized);
645 if (MinSrc.convertFromAPInt(Min, !Unsigned, APFloat::rmTowardZero) &
649 MinSrc = APFloat::getInf(SrcSema,
true);
653 MinSrc.subtract(APFloat(SrcSema, 1), APFloat::rmTowardNegative);
655 APSInt Max = APSInt::getMaxValue(Width, Unsigned);
656 APFloat MaxSrc(SrcSema, APFloat::uninitialized);
657 if (MaxSrc.convertFromAPInt(Max, !Unsigned, APFloat::rmTowardZero) &
661 MaxSrc = APFloat::getInf(SrcSema,
false);
665 MaxSrc.add(APFloat(SrcSema, 1), APFloat::rmTowardPositive);
670 const llvm::fltSemantics &
Sema =
671 CGF.getContext().getFloatTypeSemantics(SrcType);
673 MinSrc.convert(Sema, APFloat::rmTowardZero, &IsInexact);
674 MaxSrc.convert(Sema, APFloat::rmTowardZero, &IsInexact);
678 Builder.CreateFCmpOGT(Src, llvm::ConstantFP::get(VMContext, MinSrc));
680 Builder.CreateFCmpOLT(Src, llvm::ConstantFP::get(VMContext, MaxSrc));
681 Check =
Builder.CreateAnd(GE, LE);
698 if (CGF.getContext().getFloatingTypeOrder(OrigSrcType, DstType) != 1)
702 "should not check conversion from __half, it has the lowest rank");
704 const llvm::fltSemantics &DstSema =
705 CGF.getContext().getFloatTypeSemantics(DstType);
706 APFloat MinBad = APFloat::getLargest(DstSema,
false);
707 APFloat MaxBad = APFloat::getInf(DstSema,
false);
710 MinBad.convert(SrcSema, APFloat::rmTowardZero, &IsInexact);
711 MaxBad.convert(SrcSema, APFloat::rmTowardZero, &IsInexact);
713 Value *AbsSrc = CGF.EmitNounwindRuntimeCall(
716 Builder.CreateFCmpOGT(AbsSrc, llvm::ConstantFP::get(VMContext, MinBad));
718 Builder.CreateFCmpOLT(AbsSrc, llvm::ConstantFP::get(VMContext, MaxBad));
723 llvm::Constant *StaticArgs[] = {CGF.EmitCheckSourceLocation(Loc),
724 CGF.EmitCheckTypeDescriptor(OrigSrcType),
725 CGF.EmitCheckTypeDescriptor(DstType)};
726 CGF.EmitCheck(std::make_pair(Check, SanitizerKind::FloatCastOverflow),
727 "float_cast_overflow", StaticArgs, OrigSrc);
735 return EmitScalarConversion(Src, SrcType, DstType, Loc,
false);
741 bool TreatBooleanAsSigned) {
744 if (SrcType == DstType)
return Src;
754 return EmitConversionToBool(Src, SrcType);
759 if (SrcType->
isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
761 if (DstTy->isFloatingPointTy()) {
762 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns)
764 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16, DstTy),
770 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns) {
772 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16,
776 Src =
Builder.CreateFPExt(Src, CGF.CGM.FloatTy,
"conv");
778 SrcType = CGF.getContext().FloatTy;
790 if (isa<llvm::PointerType>(DstTy)) {
792 if (isa<llvm::PointerType>(SrcTy))
793 return Builder.CreateBitCast(Src, DstTy,
"conv");
795 assert(SrcType->
isIntegerType() &&
"Not ptr->ptr or int->ptr conversion?");
801 Builder.CreateIntCast(Src, MiddleTy, InputSigned,
"conv");
803 return Builder.CreateIntToPtr(IntResult, DstTy,
"conv");
806 if (isa<llvm::PointerType>(SrcTy)) {
808 assert(isa<llvm::IntegerType>(DstTy) &&
"not ptr->int?");
809 return Builder.CreatePtrToInt(Src, DstTy,
"conv");
818 "Splatted expr doesn't match with vector element type?");
821 unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
822 return Builder.CreateVectorSplat(NumElements, Src,
"splat");
826 if (isa<llvm::VectorType>(SrcTy) ||
827 isa<llvm::VectorType>(DstTy))
828 return Builder.CreateBitCast(Src, DstTy,
"conv");
831 Value *Res =
nullptr;
836 if (CGF.SanOpts.has(SanitizerKind::FloatCastOverflow) &&
838 EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType, DstTy,
842 if (DstType->
isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
844 if (SrcTy->isFloatingPointTy()) {
847 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns)
849 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16, SrcTy), Src);
851 return Builder.CreateFPTrunc(Src, DstTy);
856 if (isa<llvm::IntegerType>(SrcTy)) {
861 if (isa<llvm::IntegerType>(DstTy))
862 Res =
Builder.CreateIntCast(Src, DstTy, InputSigned,
"conv");
863 else if (InputSigned)
864 Res =
Builder.CreateSIToFP(Src, DstTy,
"conv");
866 Res =
Builder.CreateUIToFP(Src, DstTy,
"conv");
867 }
else if (isa<llvm::IntegerType>(DstTy)) {
868 assert(SrcTy->isFloatingPointTy() &&
"Unknown real conversion");
870 Res =
Builder.CreateFPToSI(Src, DstTy,
"conv");
872 Res =
Builder.CreateFPToUI(Src, DstTy,
"conv");
874 assert(SrcTy->isFloatingPointTy() && DstTy->isFloatingPointTy() &&
875 "Unknown real conversion");
876 if (DstTy->getTypeID() < SrcTy->getTypeID())
877 Res =
Builder.CreateFPTrunc(Src, DstTy,
"conv");
879 Res =
Builder.CreateFPExt(Src, DstTy,
"conv");
882 if (DstTy != ResTy) {
883 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns) {
884 assert(ResTy->isIntegerTy(16) &&
"Only half FP requires extra conversion");
886 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16, CGF.CGM.FloatTy),
889 Res =
Builder.CreateFPTrunc(Res, ResTy,
"conv");
898 Value *ScalarExprEmitter::EmitComplexToScalarConversion(
907 Src.first = EmitScalarConversion(Src.first, SrcTy, DstTy, Loc);
908 Src.second = EmitScalarConversion(Src.second, SrcTy, DstTy, Loc);
909 return Builder.CreateOr(Src.first, Src.second,
"tobool");
916 return EmitScalarConversion(Src.first, SrcTy, DstTy, Loc);
920 return CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(Ty), Ty);
927 void ScalarExprEmitter::EmitBinOpCheck(
928 ArrayRef<std::pair<Value *, SanitizerMask>> Checks,
const BinOpInfo &Info) {
929 assert(CGF.IsSanitizerScope);
938 StaticData.push_back(CGF.EmitCheckSourceLocation(Info.E->getExprLoc()));
941 CheckName =
"negate_overflow";
942 StaticData.push_back(CGF.EmitCheckTypeDescriptor(UO->
getType()));
943 DynamicData.push_back(Info.RHS);
947 CheckName =
"shift_out_of_bounds";
949 StaticData.push_back(
951 StaticData.push_back(
955 CheckName =
"divrem_overflow";
956 StaticData.push_back(CGF.EmitCheckTypeDescriptor(Info.Ty));
960 case BO_Add: CheckName =
"add_overflow";
break;
961 case BO_Sub: CheckName =
"sub_overflow";
break;
962 case BO_Mul: CheckName =
"mul_overflow";
break;
963 default: llvm_unreachable(
"unexpected opcode for bin op check");
965 StaticData.push_back(CGF.EmitCheckTypeDescriptor(Info.Ty));
967 DynamicData.push_back(Info.LHS);
968 DynamicData.push_back(Info.RHS);
971 CGF.EmitCheck(Checks, CheckName, StaticData, DynamicData);
978 Value *ScalarExprEmitter::VisitExpr(
Expr *E) {
979 CGF.ErrorUnsupported(E,
"scalar expression");
982 return llvm::UndefValue::get(CGF.ConvertType(E->
getType()));
993 llvm::VectorType *LTy = cast<llvm::VectorType>(LHS->getType());
994 unsigned LHSElts = LTy->getNumElements();
997 Mask = CGF.EmitScalarExpr(E->
getExpr(2));
1001 for (
unsigned i = 0; i != LHSElts; ++i) {
1002 concat.push_back(
Builder.getInt32(2*i));
1003 concat.push_back(
Builder.getInt32(2*i+1));
1006 Value* CV = llvm::ConstantVector::get(concat);
1007 LHS =
Builder.CreateShuffleVector(LHS, RHS, CV,
"concat");
1013 llvm::VectorType *MTy = cast<llvm::VectorType>(Mask->getType());
1017 llvm::ConstantInt::get(MTy, llvm::NextPowerOf2(LHSElts - 1) - 1);
1018 Mask =
Builder.CreateAnd(Mask, MaskBits,
"mask");
1026 llvm::VectorType *RTy = llvm::VectorType::get(LTy->getElementType(),
1027 MTy->getNumElements());
1028 Value* NewV = llvm::UndefValue::get(RTy);
1029 for (
unsigned i = 0, e = MTy->getNumElements(); i != e; ++i) {
1030 Value *IIndx = llvm::ConstantInt::get(CGF.SizeTy, i);
1031 Value *Indx =
Builder.CreateExtractElement(Mask, IIndx,
"shuf_idx");
1033 Value *VExt =
Builder.CreateExtractElement(LHS, Indx,
"shuf_elt");
1034 NewV =
Builder.CreateInsertElement(NewV, VExt, IIndx,
"shuf_ins");
1046 if (Idx.isSigned() && Idx.isAllOnesValue())
1047 indices.push_back(llvm::UndefValue::get(CGF.Int32Ty));
1049 indices.push_back(
Builder.getInt32(Idx.getZExtValue()));
1052 Value *SV = llvm::ConstantVector::get(indices);
1053 return Builder.CreateShuffleVector(V1, V2, SV,
"shuffle");
1064 if (SrcType == DstType)
return Src;
1067 "ConvertVector source type must be a vector");
1069 "ConvertVector destination type must be a vector");
1081 assert(SrcTy->isVectorTy() &&
1082 "ConvertVector source IR type must be a vector");
1083 assert(DstTy->isVectorTy() &&
1084 "ConvertVector destination IR type must be a vector");
1086 llvm::Type *SrcEltTy = SrcTy->getVectorElementType(),
1087 *DstEltTy = DstTy->getVectorElementType();
1089 if (DstEltType->isBooleanType()) {
1090 assert((SrcEltTy->isFloatingPointTy() ||
1091 isa<llvm::IntegerType>(SrcEltTy)) &&
"Unknown boolean conversion");
1093 llvm::Value *Zero = llvm::Constant::getNullValue(SrcTy);
1094 if (SrcEltTy->isFloatingPointTy()) {
1095 return Builder.CreateFCmpUNE(Src, Zero,
"tobool");
1097 return Builder.CreateICmpNE(Src, Zero,
"tobool");
1102 Value *Res =
nullptr;
1104 if (isa<llvm::IntegerType>(SrcEltTy)) {
1106 if (isa<llvm::IntegerType>(DstEltTy))
1107 Res =
Builder.CreateIntCast(Src, DstTy, InputSigned,
"conv");
1108 else if (InputSigned)
1109 Res =
Builder.CreateSIToFP(Src, DstTy,
"conv");
1111 Res =
Builder.CreateUIToFP(Src, DstTy,
"conv");
1112 }
else if (isa<llvm::IntegerType>(DstEltTy)) {
1113 assert(SrcEltTy->isFloatingPointTy() &&
"Unknown real conversion");
1114 if (DstEltType->isSignedIntegerOrEnumerationType())
1115 Res =
Builder.CreateFPToSI(Src, DstTy,
"conv");
1117 Res =
Builder.CreateFPToUI(Src, DstTy,
"conv");
1119 assert(SrcEltTy->isFloatingPointTy() && DstEltTy->isFloatingPointTy() &&
1120 "Unknown real conversion");
1121 if (DstEltTy->getTypeID() < SrcEltTy->getTypeID())
1122 Res =
Builder.CreateFPTrunc(Src, DstTy,
"conv");
1124 Res =
Builder.CreateFPExt(Src, DstTy,
"conv");
1134 CGF.EmitScalarExpr(E->
getBase());
1140 return EmitLoadOfLValue(E);
1144 TestAndClearIgnoreResultAssign();
1151 return EmitLoadOfLValue(E);
1156 Value *Idx = Visit(E->
getIdx());
1159 if (CGF.SanOpts.has(SanitizerKind::ArrayBounds))
1160 CGF.EmitBoundsCheck(E, E->
getBase(), Idx, IdxTy,
true);
1162 return Builder.CreateExtractElement(Base, Idx,
"vecext");
1165 static llvm::Constant *
getMaskElt(llvm::ShuffleVectorInst *SVI,
unsigned Idx,
1167 int MV = SVI->getMaskValue(Idx);
1169 return llvm::UndefValue::get(I32Ty);
1170 return llvm::ConstantInt::get(I32Ty, Off+MV);
1174 if (C->getBitWidth() != 32) {
1175 assert(llvm::ConstantInt::isValueValidForType(I32Ty,
1176 C->getZExtValue()) &&
1177 "Index operand too large for shufflevector mask!");
1178 return llvm::ConstantInt::get(I32Ty, C->getZExtValue());
1183 Value *ScalarExprEmitter::VisitInitListExpr(
InitListExpr *E) {
1184 bool Ignore = TestAndClearIgnoreResultAssign();
1186 assert (Ignore ==
false &&
"init list ignored");
1190 CGF.ErrorUnsupported(E,
"GNU array range designator extension");
1192 llvm::VectorType *VType =
1193 dyn_cast<llvm::VectorType>(ConvertType(E->
getType()));
1196 if (NumInitElements == 0) {
1198 return EmitNullValue(E->
getType());
1204 unsigned ResElts = VType->getNumElements();
1211 unsigned CurIdx = 0;
1212 bool VIsUndefShuffle =
false;
1214 for (
unsigned i = 0; i != NumInitElements; ++i) {
1216 Value *Init = Visit(IE);
1219 llvm::VectorType *VVT = dyn_cast<llvm::VectorType>(Init->getType());
1225 if (isa<ExtVectorElementExpr>(IE)) {
1226 llvm::ExtractElementInst *EI = cast<llvm::ExtractElementInst>(Init);
1228 if (EI->getVectorOperandType()->getNumElements() == ResElts) {
1229 llvm::ConstantInt *
C = cast<llvm::ConstantInt>(EI->getIndexOperand());
1230 Value *LHS =
nullptr, *RHS =
nullptr;
1235 Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
1237 LHS = EI->getVectorOperand();
1239 VIsUndefShuffle =
true;
1240 }
else if (VIsUndefShuffle) {
1242 llvm::ShuffleVectorInst *SVV = cast<llvm::ShuffleVectorInst>(V);
1243 for (
unsigned j = 0; j != CurIdx; ++j)
1244 Args.push_back(
getMaskElt(SVV, j, 0, CGF.Int32Ty));
1245 Args.push_back(
Builder.getInt32(ResElts + C->getZExtValue()));
1246 Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
1248 LHS = cast<llvm::ShuffleVectorInst>(V)->getOperand(0);
1249 RHS = EI->getVectorOperand();
1250 VIsUndefShuffle =
false;
1252 if (!Args.empty()) {
1253 llvm::Constant *Mask = llvm::ConstantVector::get(Args);
1254 V =
Builder.CreateShuffleVector(LHS, RHS, Mask);
1260 V =
Builder.CreateInsertElement(V, Init,
Builder.getInt32(CurIdx),
1262 VIsUndefShuffle =
false;
1267 unsigned InitElts = VVT->getNumElements();
1272 unsigned Offset = (CurIdx == 0) ? 0 : ResElts;
1273 if (isa<ExtVectorElementExpr>(IE)) {
1274 llvm::ShuffleVectorInst *SVI = cast<llvm::ShuffleVectorInst>(Init);
1275 Value *SVOp = SVI->getOperand(0);
1276 llvm::VectorType *OpTy = cast<llvm::VectorType>(SVOp->getType());
1278 if (OpTy->getNumElements() == ResElts) {
1279 for (
unsigned j = 0; j != CurIdx; ++j) {
1282 if (VIsUndefShuffle) {
1283 Args.push_back(
getMaskElt(cast<llvm::ShuffleVectorInst>(V), j, 0,
1286 Args.push_back(
Builder.getInt32(j));
1289 for (
unsigned j = 0, je = InitElts; j != je; ++j)
1290 Args.push_back(
getMaskElt(SVI, j, Offset, CGF.Int32Ty));
1291 Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
1293 if (VIsUndefShuffle)
1294 V = cast<llvm::ShuffleVectorInst>(V)->getOperand(0);
1303 for (
unsigned j = 0; j != InitElts; ++j)
1304 Args.push_back(
Builder.getInt32(j));
1305 Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
1306 llvm::Constant *Mask = llvm::ConstantVector::get(Args);
1307 Init =
Builder.CreateShuffleVector(Init, llvm::UndefValue::get(VVT),
1311 for (
unsigned j = 0; j != CurIdx; ++j)
1312 Args.push_back(
Builder.getInt32(j));
1313 for (
unsigned j = 0; j != InitElts; ++j)
1314 Args.push_back(
Builder.getInt32(j+Offset));
1315 Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
1322 llvm::Constant *Mask = llvm::ConstantVector::get(Args);
1323 V =
Builder.CreateShuffleVector(V, Init, Mask,
"vecinit");
1324 VIsUndefShuffle = isa<llvm::UndefValue>(Init);
1333 for (; CurIdx < ResElts; ++CurIdx) {
1334 Value *Idx =
Builder.getInt32(CurIdx);
1335 llvm::Value *Init = llvm::Constant::getNullValue(EltTy);
1336 V =
Builder.CreateInsertElement(V, Init, Idx,
"vecinit");
1364 Value *ScalarExprEmitter::VisitCastExpr(
CastExpr *CE) {
1370 TestAndClearIgnoreResultAssign();
1376 case CK_Dependent: llvm_unreachable(
"dependent cast kind in IR gen!");
1378 llvm_unreachable(
"builtin functions are handled elsewhere");
1382 Address Addr = EmitLValue(E).getAddress();
1383 Addr =
Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));
1384 LValue LV = CGF.MakeAddrLValue(Addr, DestTy);
1385 return EmitLoadOfLValue(LV, CE->
getExprLoc());
1392 Value *Src = Visit(const_cast<Expr*>(E));
1395 if (SrcTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() &&
1396 SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace()) {
1397 llvm_unreachable(
"wrong cast for pointers in different address spaces"
1398 "(must be an address space cast)!");
1401 if (CGF.SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
1403 CGF.EmitVTablePtrCheckForCast(PT->getPointeeType(), Src,
1409 return Builder.CreateBitCast(Src, DstTy);
1412 Value *Src = Visit(const_cast<Expr*>(E));
1413 return Builder.CreateAddrSpaceCast(Src, ConvertType(DestTy));
1419 return Visit(const_cast<Expr*>(E));
1423 assert(DerivedClassDecl &&
"BaseToDerived arg isn't a C++ object pointer!");
1425 Address Base = CGF.EmitPointerWithAlignment(E);
1427 CGF.GetAddressOfDerivedClass(Base, DerivedClassDecl,
1429 CGF.ShouldNullCheckClassCastValue(CE));
1433 if (CGF.sanitizePerformTypeCheck())
1437 if (CGF.SanOpts.has(SanitizerKind::CFIDerivedCast))
1450 return CGF.EmitPointerWithAlignment(CE).getPointer();
1454 Address V = CGF.EmitPointerWithAlignment(E);
1456 return CGF.EmitDynamicCast(V, DCE);
1460 return CGF.EmitArrayToPointerDecay(E).getPointer();
1462 return EmitLValue(E).getPointer();
1465 if (MustVisitNullValue(E))
1468 return llvm::ConstantPointerNull::get(
1469 cast<llvm::PointerType>(ConvertType(DestTy)));
1472 if (MustVisitNullValue(E))
1476 return CGF.CGM.getCXXABI().EmitNullMemberPointer(MPT);
1482 Value *Src = Visit(E);
1490 return CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, Src);
1494 return CGF.EmitARCRetainScalarExpr(E);
1496 return CGF.EmitObjCConsumeObject(E->
getType(), Visit(E));
1499 value = CGF.EmitARCRetainAutoreleasedReturnValue(value);
1500 return CGF.EmitObjCConsumeObject(E->
getType(), value);
1503 return CGF.EmitARCExtendBlockObject(E);
1506 return CGF.EmitBlockCopyAndAutorelease(Visit(E), E->
getType());
1516 llvm_unreachable(
"scalar cast to non-scalar value");
1519 assert(CGF.getContext().hasSameUnqualifiedType(E->
getType(), DestTy));
1520 assert(E->
isGLValue() &&
"lvalue-to-rvalue applied to r-value!");
1521 return Visit(const_cast<Expr*>(E));
1524 Value *Src = Visit(const_cast<Expr*>(E));
1531 Builder.CreateIntCast(Src, MiddleTy, InputSigned,
"conv");
1533 return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy));
1536 assert(!DestTy->
isBooleanType() &&
"bool should use PointerToBool");
1537 return Builder.CreatePtrToInt(Visit(E), ConvertType(DestTy));
1540 CGF.EmitIgnoredExpr(E);
1545 Value *Elt = Visit(const_cast<Expr*>(E));
1547 unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
1548 return Builder.CreateVectorSplat(NumElements, Elt,
"splat");
1555 return EmitScalarConversion(Visit(E), E->
getType(), DestTy,
1558 return EmitScalarConversion(Visit(E), E->
getType(), DestTy,
1562 return EmitIntToBoolConversion(Visit(E));
1564 return EmitPointerToBoolConversion(Visit(E));
1566 return EmitFloatToBoolConversion(Visit(E));
1570 return CGF.CGM.getCXXABI().EmitMemberPointerIsNotNull(CGF, MemPtr, MPT);
1575 return CGF.EmitComplexExpr(E,
false,
true).first;
1582 return EmitComplexToScalarConversion(V, E->
getType(), DestTy,
1587 assert(DestTy->
isEventT() &&
"CK_ZeroToOCLEvent cast on non-event type");
1588 return llvm::Constant::getNullValue(ConvertType(DestTy));
1593 llvm_unreachable(
"unknown scalar cast");
1596 Value *ScalarExprEmitter::VisitStmtExpr(
const StmtExpr *E) {
1602 return CGF.EmitLoadOfScalar(CGF.MakeAddrLValue(RetAlloca, E->
getType()),
1614 BinOp.RHS = llvm::ConstantInt::get(InVal->getType(), 1,
false);
1617 BinOp.FPContractable =
false;
1622 llvm::Value *ScalarExprEmitter::EmitIncDecConsiderOverflowBehavior(
1625 llvm::ConstantInt::get(InVal->getType(), IsInc ? 1 : -1,
true);
1626 StringRef
Name = IsInc ?
"inc" :
"dec";
1627 switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
1629 return Builder.CreateAdd(InVal, Amount, Name);
1631 if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
1632 return Builder.CreateNSWAdd(InVal, Amount, Name);
1637 llvm_unreachable(
"Unknown SignedOverflowBehaviorTy");
1642 bool isInc,
bool isPre) {
1645 llvm::PHINode *atomicPHI =
nullptr;
1649 int amount = (isInc ? 1 : -1);
1652 type = atomicTy->getValueType();
1657 ->setAtomic(llvm::SequentiallyConsistent);
1662 return Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg,
1663 LV.
getPointer(), True, llvm::SequentiallyConsistent);
1670 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow)) &&
1671 CGF.getLangOpts().getSignedOverflowBehavior() !=
1673 llvm::AtomicRMWInst::BinOp aop = isInc ? llvm::AtomicRMWInst::Add :
1674 llvm::AtomicRMWInst::Sub;
1675 llvm::Instruction::BinaryOps op = isInc ? llvm::Instruction::Add :
1676 llvm::Instruction::Sub;
1678 llvm::ConstantInt::get(ConvertType(type), 1,
true), type);
1680 LV.
getPointer(), amt, llvm::SequentiallyConsistent);
1681 return isPre ?
Builder.CreateBinOp(op, old, amt) : old;
1683 value = EmitLoadOfLValue(LV, E->
getExprLoc());
1686 llvm::BasicBlock *startBB =
Builder.GetInsertBlock();
1687 llvm::BasicBlock *opBB = CGF.createBasicBlock(
"atomic_op", CGF.CurFn);
1688 value = CGF.EmitToMemory(value, type);
1691 atomicPHI =
Builder.CreatePHI(value->getType(), 2);
1692 atomicPHI->addIncoming(value, startBB);
1695 value = EmitLoadOfLValue(LV, E->
getExprLoc());
1713 bool CanOverflow = value->getType()->getIntegerBitWidth() >=
1714 CGF.IntTy->getIntegerBitWidth();
1716 value = EmitIncDecConsiderOverflowBehavior(E, value, isInc);
1718 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow)) {
1722 llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount,
true);
1723 value =
Builder.CreateAdd(value, amt, isInc ?
"inc" :
"dec");
1732 = CGF.getContext().getAsVariableArrayType(type)) {
1734 if (!isInc) numElts =
Builder.CreateNSWNeg(numElts,
"vla.negsize");
1735 if (CGF.getLangOpts().isSignedOverflowDefined())
1736 value =
Builder.CreateGEP(value, numElts,
"vla.inc");
1738 value =
Builder.CreateInBoundsGEP(value, numElts,
"vla.inc");
1744 value = CGF.EmitCastToVoidPtr(value);
1745 if (CGF.getLangOpts().isSignedOverflowDefined())
1746 value =
Builder.CreateGEP(value, amt,
"incdec.funcptr");
1748 value =
Builder.CreateInBoundsGEP(value, amt,
"incdec.funcptr");
1749 value =
Builder.CreateBitCast(value, input->getType());
1754 if (CGF.getLangOpts().isSignedOverflowDefined())
1755 value =
Builder.CreateGEP(value, amt,
"incdec.ptr");
1757 value =
Builder.CreateInBoundsGEP(value, amt,
"incdec.ptr");
1763 llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount);
1765 value =
Builder.CreateAdd(value, amt, isInc ?
"inc" :
"dec");
1769 llvm::ConstantFP::get(value->getType(), amount),
1770 isInc ?
"inc" :
"dec");
1778 if (type->
isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
1780 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns) {
1782 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16,
1784 input,
"incdec.conv");
1786 value =
Builder.CreateFPExt(input, CGF.CGM.FloatTy,
"incdec.conv");
1790 if (value->getType()->isFloatTy())
1791 amt = llvm::ConstantFP::get(VMContext,
1792 llvm::APFloat(static_cast<float>(amount)));
1793 else if (value->getType()->isDoubleTy())
1794 amt = llvm::ConstantFP::get(VMContext,
1795 llvm::APFloat(static_cast<double>(amount)));
1798 llvm::APFloat F(static_cast<float>(amount));
1802 F.convert(value->getType()->isHalfTy()
1803 ? CGF.getTarget().getHalfFormat()
1804 : CGF.getTarget().getLongDoubleFormat(),
1805 llvm::APFloat::rmTowardZero, &ignored);
1806 amt = llvm::ConstantFP::get(VMContext, F);
1808 value =
Builder.CreateFAdd(value, amt, isInc ?
"inc" :
"dec");
1810 if (type->
isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
1811 if (!CGF.getContext().getLangOpts().HalfArgsAndReturns) {
1813 CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16,
1815 value,
"incdec.conv");
1817 value =
Builder.CreateFPTrunc(value, input->getType(),
"incdec.conv");
1824 value = CGF.EmitCastToVoidPtr(value);
1827 if (!isInc) size = -size;
1829 llvm::ConstantInt::get(CGF.SizeTy, size.
getQuantity());
1831 if (CGF.getLangOpts().isSignedOverflowDefined())
1832 value =
Builder.CreateGEP(value, sizeValue,
"incdec.objptr");
1834 value =
Builder.CreateInBoundsGEP(value, sizeValue,
"incdec.objptr");
1835 value =
Builder.CreateBitCast(value, input->getType());
1839 llvm::BasicBlock *opBB =
Builder.GetInsertBlock();
1840 llvm::BasicBlock *contBB = CGF.createBasicBlock(
"atomic_cont", CGF.CurFn);
1841 auto Pair = CGF.EmitAtomicCompareExchange(
1845 atomicPHI->addIncoming(old, opBB);
1846 Builder.CreateCondBr(success, contBB, opBB);
1847 Builder.SetInsertPoint(contBB);
1848 return isPre ? value : input;
1853 CGF.EmitStoreThroughBitfieldLValue(
RValue::get(value), LV, &value);
1855 CGF.EmitStoreThroughLValue(
RValue::get(value), LV);
1859 return isPre ? value : input;
1864 Value *ScalarExprEmitter::VisitUnaryMinus(
const UnaryOperator *E) {
1865 TestAndClearIgnoreResultAssign();
1870 if (BinOp.RHS->getType()->isFPOrFPVectorTy())
1871 BinOp.LHS = llvm::ConstantFP::getZeroValueForNegation(BinOp.RHS->getType());
1873 BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
1876 BinOp.FPContractable =
false;
1878 return EmitSub(BinOp);
1881 Value *ScalarExprEmitter::VisitUnaryNot(
const UnaryOperator *E) {
1882 TestAndClearIgnoreResultAssign();
1884 return Builder.CreateNot(Op,
"neg");
1887 Value *ScalarExprEmitter::VisitUnaryLNot(
const UnaryOperator *E) {
1891 Value *Zero = llvm::Constant::getNullValue(Oper->getType());
1893 if (Oper->getType()->isFPOrFPVectorTy())
1894 Result =
Builder.CreateFCmp(llvm::CmpInst::FCMP_OEQ, Oper, Zero,
"cmp");
1896 Result =
Builder.CreateICmp(llvm::CmpInst::ICMP_EQ, Oper, Zero,
"cmp");
1897 return Builder.CreateSExt(Result, ConvertType(E->
getType()),
"sext");
1901 Value *BoolVal = CGF.EvaluateExprAsBool(E->
getSubExpr());
1906 BoolVal =
Builder.CreateNot(BoolVal,
"lnot");
1909 return Builder.CreateZExt(BoolVal, ConvertType(E->
getType()),
"lnot.ext");
1912 Value *ScalarExprEmitter::VisitOffsetOfExpr(
OffsetOfExpr *E) {
1921 llvm::Value* Result = llvm::Constant::getNullValue(ResultType);
1923 for (
unsigned i = 0; i != n; ++i) {
1932 Idx =
Builder.CreateIntCast(Idx, ResultType, IdxSigned,
"conv");
1936 CGF.getContext().getAsArrayType(CurrentType)->getElementType();
1939 llvm::Value* ElemSize = llvm::ConstantInt::get(ResultType,
1940 CGF.getContext().getTypeSizeInChars(CurrentType).getQuantity());
1943 Offset =
Builder.CreateMul(Idx, ElemSize);
1957 Field != FieldEnd; ++Field, ++i) {
1958 if (*Field == MemberDecl)
1961 assert(i < RL.
getFieldCount() &&
"offsetof field in wrong type");
1965 CGF.getContext().getCharWidth();
1966 Offset = llvm::ConstantInt::get(ResultType, OffsetInt);
1969 CurrentType = MemberDecl->
getType();
1974 llvm_unreachable(
"dependent __builtin_offsetof");
1978 CGF.ErrorUnsupported(E,
"virtual base in offsetof");
1992 Offset = llvm::ConstantInt::get(ResultType, OffsetInt.getQuantity());
1996 Result =
Builder.CreateAdd(Result, Offset);
2004 ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
2009 CGF.getContext().getAsVariableArrayType(TypeToSize)) {
2012 CGF.EmitVariablyModifiedType(TypeToSize);
2021 std::tie(numElts, eltType) = CGF.getVLASize(VAT);
2026 CharUnits eltSize = CGF.getContext().getTypeSizeInChars(eltType);
2027 if (!eltSize.
isOne())
2028 size = CGF.Builder.CreateNUWMul(CGF.CGM.getSize(eltSize), numElts);
2035 .toCharUnitsFromBits(CGF.getContext().getOpenMPDefaultSimdAlign(
2038 return llvm::ConstantInt::get(CGF.SizeTy, Alignment);
2046 Value *ScalarExprEmitter::VisitUnaryReal(
const UnaryOperator *E) {
2053 return CGF.EmitLoadOfLValue(CGF.EmitLValue(E),
2057 return CGF.EmitComplexExpr(Op,
false,
true).first;
2063 Value *ScalarExprEmitter::VisitUnaryImag(
const UnaryOperator *E) {
2070 return CGF.EmitLoadOfLValue(CGF.EmitLValue(E),
2074 return CGF.EmitComplexExpr(Op,
true,
false).second;
2082 CGF.EmitScalarExpr(Op,
true);
2083 return llvm::Constant::getNullValue(ConvertType(E->
getType()));
2090 BinOpInfo ScalarExprEmitter::EmitBinOps(
const BinaryOperator *E) {
2091 TestAndClearIgnoreResultAssign();
2093 Result.LHS = Visit(E->
getLHS());
2094 Result.RHS = Visit(E->
getRHS());
2102 LValue ScalarExprEmitter::EmitCompoundAssignLValue(
2104 Value *(ScalarExprEmitter::*Func)(
const BinOpInfo &),
2110 return CGF.EmitScalarCompoundAssignWithComplex(E, Result);
2114 OpInfo.RHS = Visit(E->
getRHS());
2122 llvm::PHINode *atomicPHI =
nullptr;
2124 QualType type = atomicTy->getValueType();
2127 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow)) &&
2128 CGF.getLangOpts().getSignedOverflowBehavior() !=
2130 llvm::AtomicRMWInst::BinOp aop = llvm::AtomicRMWInst::BAD_BINOP;
2131 switch (OpInfo.Opcode) {
2139 aop = llvm::AtomicRMWInst::Add;
2142 aop = llvm::AtomicRMWInst::Sub;
2148 aop = llvm::AtomicRMWInst::Xor;
2151 aop = llvm::AtomicRMWInst::Or;
2154 llvm_unreachable(
"Invalid compound assignment type");
2156 if (aop != llvm::AtomicRMWInst::BAD_BINOP) {
2158 EmitScalarConversion(OpInfo.RHS, E->
getRHS()->
getType(), LHSTy,
2162 llvm::SequentiallyConsistent);
2168 llvm::BasicBlock *startBB =
Builder.GetInsertBlock();
2169 llvm::BasicBlock *opBB = CGF.createBasicBlock(
"atomic_op", CGF.CurFn);
2170 OpInfo.LHS = EmitLoadOfLValue(LHSLV, E->
getExprLoc());
2171 OpInfo.LHS = CGF.EmitToMemory(OpInfo.LHS, type);
2174 atomicPHI =
Builder.CreatePHI(OpInfo.LHS->getType(), 2);
2175 atomicPHI->addIncoming(OpInfo.LHS, startBB);
2176 OpInfo.LHS = atomicPHI;
2179 OpInfo.LHS = EmitLoadOfLValue(LHSLV, E->
getExprLoc());
2186 Result = (this->*Func)(OpInfo);
2193 llvm::BasicBlock *opBB =
Builder.GetInsertBlock();
2194 llvm::BasicBlock *contBB = CGF.createBasicBlock(
"atomic_cont", CGF.CurFn);
2195 auto Pair = CGF.EmitAtomicCompareExchange(
2197 llvm::Value *old = CGF.EmitToMemory(Pair.first.getScalarVal(), LHSTy);
2199 atomicPHI->addIncoming(old, opBB);
2200 Builder.CreateCondBr(success, contBB, opBB);
2201 Builder.SetInsertPoint(contBB);
2210 CGF.EmitStoreThroughBitfieldLValue(
RValue::get(Result), LHSLV, &Result);
2212 CGF.EmitStoreThroughLValue(
RValue::get(Result), LHSLV);
2218 Value *(ScalarExprEmitter::*Func)(
const BinOpInfo &)) {
2219 bool Ignore = TestAndClearIgnoreResultAssign();
2221 LValue LHS = EmitCompoundAssignLValue(E, Func, RHS);
2228 if (!CGF.getLangOpts().CPlusPlus)
2236 return EmitLoadOfLValue(LHS, E->
getExprLoc());
2239 void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
2240 const BinOpInfo &Ops,
llvm::Value *Zero,
bool isDiv) {
2243 if (CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero)) {
2244 Checks.push_back(std::make_pair(
Builder.CreateICmpNE(Ops.RHS, Zero),
2245 SanitizerKind::IntegerDivideByZero));
2248 if (CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow) &&
2249 Ops.Ty->hasSignedIntegerRepresentation()) {
2250 llvm::IntegerType *Ty = cast<llvm::IntegerType>(Zero->getType());
2253 Builder.getInt(llvm::APInt::getSignedMinValue(Ty->getBitWidth()));
2254 llvm::Value *NegOne = llvm::ConstantInt::get(Ty, -1ULL);
2260 std::make_pair(NotOverflow, SanitizerKind::SignedIntegerOverflow));
2263 if (Checks.size() > 0)
2264 EmitBinOpCheck(Checks, Ops);
2267 Value *ScalarExprEmitter::EmitDiv(
const BinOpInfo &Ops) {
2270 if ((CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero) ||
2271 CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) &&
2272 Ops.Ty->isIntegerType()) {
2273 llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
2274 EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero,
true);
2275 }
else if (CGF.SanOpts.has(SanitizerKind::FloatDivideByZero) &&
2276 Ops.Ty->isRealFloatingType()) {
2277 llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
2279 EmitBinOpCheck(std::make_pair(NonZero, SanitizerKind::FloatDivideByZero),
2284 if (Ops.LHS->getType()->isFPOrFPVectorTy()) {
2286 if (CGF.getLangOpts().OpenCL) {
2289 if (ValTy->isFloatTy() ||
2290 (isa<llvm::VectorType>(ValTy) &&
2291 cast<llvm::VectorType>(ValTy)->getElementType()->isFloatTy()))
2292 CGF.SetFPAccuracy(Val, 2.5);
2296 else if (Ops.Ty->hasUnsignedIntegerRepresentation())
2297 return Builder.CreateUDiv(Ops.LHS, Ops.RHS,
"div");
2299 return Builder.CreateSDiv(Ops.LHS, Ops.RHS,
"div");
2302 Value *ScalarExprEmitter::EmitRem(
const BinOpInfo &Ops) {
2304 if (CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero)) {
2306 llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
2308 if (Ops.Ty->isIntegerType())
2309 EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero,
false);
2312 if (Ops.Ty->hasUnsignedIntegerRepresentation())
2313 return Builder.CreateURem(Ops.LHS, Ops.RHS,
"rem");
2315 return Builder.CreateSRem(Ops.LHS, Ops.RHS,
"rem");
2318 Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(
const BinOpInfo &Ops) {
2322 bool isSigned = Ops.Ty->isSignedIntegerOrEnumerationType();
2323 switch (Ops.Opcode) {
2327 IID = isSigned ? llvm::Intrinsic::sadd_with_overflow :
2328 llvm::Intrinsic::uadd_with_overflow;
2333 IID = isSigned ? llvm::Intrinsic::ssub_with_overflow :
2334 llvm::Intrinsic::usub_with_overflow;
2339 IID = isSigned ? llvm::Intrinsic::smul_with_overflow :
2340 llvm::Intrinsic::umul_with_overflow;
2343 llvm_unreachable(
"Unsupported operation for overflow detection");
2349 llvm::Type *opTy = CGF.CGM.getTypes().ConvertType(Ops.Ty);
2351 llvm::Function *intrinsic = CGF.CGM.getIntrinsic(IID, opTy);
2353 Value *resultAndOverflow =
Builder.CreateCall(intrinsic, {Ops.LHS, Ops.RHS});
2354 Value *result =
Builder.CreateExtractValue(resultAndOverflow, 0);
2355 Value *overflow =
Builder.CreateExtractValue(resultAndOverflow, 1);
2358 const std::string *handlerName =
2359 &CGF.getLangOpts().OverflowHandler;
2360 if (handlerName->empty()) {
2363 if (!isSigned || CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) {
2366 SanitizerMask Kind = isSigned ? SanitizerKind::SignedIntegerOverflow
2367 : SanitizerKind::UnsignedIntegerOverflow;
2368 EmitBinOpCheck(std::make_pair(NotOverflow, Kind), Ops);
2370 CGF.EmitTrapCheck(
Builder.CreateNot(overflow));
2375 llvm::BasicBlock *initialBB =
Builder.GetInsertBlock();
2377 llvm::BasicBlock *continueBB = CGF.createBasicBlock(
"nooverflow", CGF.CurFn,
2378 &*std::next(insertPt));
2379 llvm::BasicBlock *overflowBB = CGF.createBasicBlock(
"overflow", CGF.CurFn);
2381 Builder.CreateCondBr(overflow, overflowBB, continueBB);
2385 Builder.SetInsertPoint(overflowBB);
2389 llvm::Type *argTypes[] = { CGF.Int64Ty, CGF.Int64Ty, Int8Ty, Int8Ty };
2390 llvm::FunctionType *handlerTy =
2391 llvm::FunctionType::get(CGF.Int64Ty, argTypes,
true);
2392 llvm::Value *handler = CGF.CGM.CreateRuntimeFunction(handlerTy, *handlerName);
2405 Builder.getInt8(cast<llvm::IntegerType>(opTy)->getBitWidth())
2408 CGF.EmitNounwindRuntimeCall(handler, handlerArgs);
2411 handlerResult =
Builder.CreateTrunc(handlerResult, opTy);
2414 Builder.SetInsertPoint(continueBB);
2415 llvm::PHINode *phi =
Builder.CreatePHI(opTy, 2);
2416 phi->addIncoming(result, initialBB);
2417 phi->addIncoming(handlerResult, overflowBB);
2424 const BinOpInfo &op,
2425 bool isSubtraction) {
2430 Value *pointer = op.LHS;
2432 Value *index = op.RHS;
2436 if (!isSubtraction && !pointer->getType()->isPointerTy()) {
2437 std::swap(pointer, index);
2438 std::swap(pointerOperand, indexOperand);
2441 unsigned width = cast<llvm::IntegerType>(index->getType())->getBitWidth();
2452 index = CGF.
Builder.CreateNeg(index,
"idx.neg");
2454 if (CGF.
SanOpts.
has(SanitizerKind::ArrayBounds))
2467 index = CGF.
Builder.CreateMul(index, objectSize);
2470 result = CGF.
Builder.CreateGEP(result, index,
"add.ptr");
2485 index = CGF.
Builder.CreateMul(index, numElements,
"vla.index");
2486 pointer = CGF.
Builder.CreateGEP(pointer, index,
"add.ptr");
2488 index = CGF.
Builder.CreateNSWMul(index, numElements,
"vla.index");
2489 pointer = CGF.
Builder.CreateInBoundsGEP(pointer, index,
"add.ptr");
2499 result = CGF.
Builder.CreateGEP(result, index,
"add.ptr");
2504 return CGF.
Builder.CreateGEP(pointer, index,
"add.ptr");
2506 return CGF.
Builder.CreateInBoundsGEP(pointer, index,
"add.ptr");
2516 bool negMul,
bool negAdd) {
2517 assert(!(negMul && negAdd) &&
"Only one of negMul and negAdd should be set.");
2519 Value *MulOp0 = MulOp->getOperand(0);
2520 Value *MulOp1 = MulOp->getOperand(1);
2524 llvm::ConstantFP::getZeroValueForNegation(MulOp0->getType()), MulOp0,
2526 }
else if (negAdd) {
2529 llvm::ConstantFP::getZeroValueForNegation(Addend->getType()), Addend,
2533 Value *FMulAdd = Builder.CreateCall(
2535 {MulOp0, MulOp1, Addend});
2536 MulOp->eraseFromParent();
2553 "Only fadd/fsub can be the root of an fmuladd.");
2556 if (!op.FPContractable)
2567 if (
auto *LHSBinOp = dyn_cast<llvm::BinaryOperator>(op.LHS)) {
2568 if (LHSBinOp->getOpcode() == llvm::Instruction::FMul &&
2569 LHSBinOp->use_empty())
2570 return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder,
false, isSub);
2572 if (
auto *RHSBinOp = dyn_cast<llvm::BinaryOperator>(op.RHS)) {
2573 if (RHSBinOp->getOpcode() == llvm::Instruction::FMul &&
2574 RHSBinOp->use_empty())
2575 return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub,
false);
2581 Value *ScalarExprEmitter::EmitAdd(
const BinOpInfo &op) {
2582 if (op.LHS->getType()->isPointerTy() ||
2583 op.RHS->getType()->isPointerTy())
2586 if (op.Ty->isSignedIntegerOrEnumerationType()) {
2587 switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
2589 return Builder.CreateAdd(op.LHS, op.RHS,
"add");
2591 if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
2592 return Builder.CreateNSWAdd(op.LHS, op.RHS,
"add");
2595 return EmitOverflowCheckedBinOp(op);
2599 if (op.Ty->isUnsignedIntegerType() &&
2600 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow))
2601 return EmitOverflowCheckedBinOp(op);
2603 if (op.LHS->getType()->isFPOrFPVectorTy()) {
2608 return Builder.CreateFAdd(op.LHS, op.RHS,
"add");
2611 return Builder.CreateAdd(op.LHS, op.RHS,
"add");
2614 Value *ScalarExprEmitter::EmitSub(
const BinOpInfo &op) {
2616 if (!op.LHS->getType()->isPointerTy()) {
2617 if (op.Ty->isSignedIntegerOrEnumerationType()) {
2618 switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
2620 return Builder.CreateSub(op.LHS, op.RHS,
"sub");
2622 if (!CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow))
2623 return Builder.CreateNSWSub(op.LHS, op.RHS,
"sub");
2626 return EmitOverflowCheckedBinOp(op);
2630 if (op.Ty->isUnsignedIntegerType() &&
2631 CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow))
2632 return EmitOverflowCheckedBinOp(op);
2634 if (op.LHS->getType()->isFPOrFPVectorTy()) {
2638 return Builder.CreateFSub(op.LHS, op.RHS,
"sub");
2641 return Builder.CreateSub(op.LHS, op.RHS,
"sub");
2646 if (!op.RHS->getType()->isPointerTy())
2653 =
Builder.CreatePtrToInt(op.LHS, CGF.PtrDiffTy,
"sub.ptr.lhs.cast");
2655 =
Builder.CreatePtrToInt(op.RHS, CGF.PtrDiffTy,
"sub.ptr.rhs.cast");
2656 Value *diffInChars =
Builder.CreateSub(LHS, RHS,
"sub.ptr.sub");
2666 = CGF.getContext().getAsVariableArrayType(elementType)) {
2668 std::tie(numElements, elementType) = CGF.getVLASize(vla);
2670 divisor = numElements;
2673 CharUnits eltSize = CGF.getContext().getTypeSizeInChars(elementType);
2674 if (!eltSize.
isOne())
2675 divisor = CGF.Builder.CreateNUWMul(CGF.CGM.getSize(eltSize), divisor);
2684 if (elementType->isVoidType() || elementType->isFunctionType())
2687 elementSize = CGF.getContext().getTypeSizeInChars(elementType);
2690 if (elementSize.
isOne())
2693 divisor = CGF.CGM.getSize(elementSize);
2699 return Builder.CreateExactSDiv(diffInChars, divisor,
"sub.ptr.div");
2702 Value *ScalarExprEmitter::GetWidthMinusOneValue(Value* LHS,Value* RHS) {
2703 llvm::IntegerType *Ty;
2704 if (llvm::VectorType *VT = dyn_cast<llvm::VectorType>(LHS->getType()))
2705 Ty = cast<llvm::IntegerType>(VT->getElementType());
2707 Ty = cast<llvm::IntegerType>(LHS->getType());
2708 return llvm::ConstantInt::get(RHS->getType(), Ty->getBitWidth() - 1);
2711 Value *ScalarExprEmitter::EmitShl(
const BinOpInfo &Ops) {
2714 Value *RHS = Ops.RHS;
2715 if (Ops.LHS->getType() != RHS->getType())
2716 RHS =
Builder.CreateIntCast(RHS, Ops.LHS->getType(),
false,
"sh_prom");
2718 bool SanitizeBase = CGF.SanOpts.has(SanitizerKind::ShiftBase) &&
2719 Ops.Ty->hasSignedIntegerRepresentation();
2720 bool SanitizeExponent = CGF.SanOpts.has(SanitizerKind::ShiftExponent);
2722 if (CGF.getLangOpts().OpenCL)
2724 Builder.CreateAnd(RHS, GetWidthMinusOneValue(Ops.LHS, RHS),
"shl.mask");
2725 else if ((SanitizeBase || SanitizeExponent) &&
2726 isa<llvm::IntegerType>(Ops.LHS->getType())) {
2729 llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
2732 if (SanitizeExponent) {
2734 std::make_pair(ValidExponent, SanitizerKind::ShiftExponent));
2741 llvm::BasicBlock *Orig =
Builder.GetInsertBlock();
2742 llvm::BasicBlock *Cont = CGF.createBasicBlock(
"cont");
2743 llvm::BasicBlock *CheckShiftBase = CGF.createBasicBlock(
"check");
2744 Builder.CreateCondBr(ValidExponent, CheckShiftBase, Cont);
2745 CGF.EmitBlock(CheckShiftBase);
2748 Builder.CreateSub(WidthMinusOne, RHS,
"shl.zeros",
2751 if (CGF.getLangOpts().CPlusPlus) {
2756 llvm::Value *One = llvm::ConstantInt::get(BitsShiftedOff->getType(), 1);
2757 BitsShiftedOff =
Builder.CreateLShr(BitsShiftedOff, One);
2759 llvm::Value *Zero = llvm::ConstantInt::get(BitsShiftedOff->getType(), 0);
2761 CGF.EmitBlock(Cont);
2762 llvm::PHINode *BaseCheck =
Builder.CreatePHI(ValidBase->getType(), 2);
2763 BaseCheck->addIncoming(
Builder.getTrue(), Orig);
2764 BaseCheck->addIncoming(ValidBase, CheckShiftBase);
2765 Checks.push_back(std::make_pair(BaseCheck, SanitizerKind::ShiftBase));
2768 assert(!Checks.empty());
2769 EmitBinOpCheck(Checks, Ops);
2772 return Builder.CreateShl(Ops.LHS, RHS,
"shl");
2775 Value *ScalarExprEmitter::EmitShr(
const BinOpInfo &Ops) {
2778 Value *RHS = Ops.RHS;
2779 if (Ops.LHS->getType() != RHS->getType())
2780 RHS =
Builder.CreateIntCast(RHS, Ops.LHS->getType(),
false,
"sh_prom");
2783 if (CGF.getLangOpts().OpenCL)
2785 Builder.CreateAnd(RHS, GetWidthMinusOneValue(Ops.LHS, RHS),
"shr.mask");
2786 else if (CGF.SanOpts.has(SanitizerKind::ShiftExponent) &&
2787 isa<llvm::IntegerType>(Ops.LHS->getType())) {
2790 Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS));
2791 EmitBinOpCheck(std::make_pair(Valid, SanitizerKind::ShiftExponent), Ops);
2794 if (Ops.Ty->hasUnsignedIntegerRepresentation())
2795 return Builder.CreateLShr(Ops.LHS, RHS,
"shr");
2796 return Builder.CreateAShr(Ops.LHS, RHS,
"shr");
2804 default: llvm_unreachable(
"unexpected element type");
2805 case BuiltinType::Char_U:
2806 case BuiltinType::UChar:
2807 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequb_p :
2808 llvm::Intrinsic::ppc_altivec_vcmpgtub_p;
2809 case BuiltinType::Char_S:
2810 case BuiltinType::SChar:
2811 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequb_p :
2812 llvm::Intrinsic::ppc_altivec_vcmpgtsb_p;
2813 case BuiltinType::UShort:
2814 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequh_p :
2815 llvm::Intrinsic::ppc_altivec_vcmpgtuh_p;
2816 case BuiltinType::Short:
2817 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequh_p :
2818 llvm::Intrinsic::ppc_altivec_vcmpgtsh_p;
2819 case BuiltinType::UInt:
2820 case BuiltinType::ULong:
2821 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequw_p :
2822 llvm::Intrinsic::ppc_altivec_vcmpgtuw_p;
2823 case BuiltinType::Int:
2824 case BuiltinType::Long:
2825 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpequw_p :
2826 llvm::Intrinsic::ppc_altivec_vcmpgtsw_p;
2827 case BuiltinType::Float:
2828 return (IT ==
VCMPEQ) ? llvm::Intrinsic::ppc_altivec_vcmpeqfp_p :
2829 llvm::Intrinsic::ppc_altivec_vcmpgtfp_p;
2834 llvm::CmpInst::Predicate UICmpOpc,
2835 llvm::CmpInst::Predicate SICmpOpc,
2836 llvm::CmpInst::Predicate FCmpOpc) {
2837 TestAndClearIgnoreResultAssign();
2844 Value *LHS = CGF.EmitScalarExpr(E->
getLHS());
2845 Value *RHS = CGF.EmitScalarExpr(E->
getRHS());
2846 Result = CGF.CGM.getCXXABI().EmitMemberPointerComparison(
2849 Value *LHS = Visit(E->
getLHS());
2850 Value *RHS = Visit(E->
getRHS());
2856 enum { CR6_EQ=0, CR6_EQ_REV, CR6_LT, CR6_LT_REV } CR6;
2861 Value *FirstVecArg = LHS,
2862 *SecondVecArg = RHS;
2869 default: llvm_unreachable(
"is not a comparison operation");
2881 std::swap(FirstVecArg, SecondVecArg);
2888 if (ElementKind == BuiltinType::Float) {
2890 ID = llvm::Intrinsic::ppc_altivec_vcmpgefp_p;
2891 std::swap(FirstVecArg, SecondVecArg);
2899 if (ElementKind == BuiltinType::Float) {
2901 ID = llvm::Intrinsic::ppc_altivec_vcmpgefp_p;
2906 std::swap(FirstVecArg, SecondVecArg);
2911 Value *CR6Param =
Builder.getInt32(CR6);
2912 llvm::Function *F = CGF.CGM.getIntrinsic(ID);
2913 Result =
Builder.CreateCall(F, {CR6Param, FirstVecArg, SecondVecArg});
2914 return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->
getType(),
2918 if (LHS->getType()->isFPOrFPVectorTy()) {
2919 Result =
Builder.CreateFCmp(FCmpOpc, LHS, RHS,
"cmp");
2921 Result =
Builder.CreateICmp(SICmpOpc, LHS, RHS,
"cmp");
2924 Result =
Builder.CreateICmp(UICmpOpc, LHS, RHS,
"cmp");
2930 return Builder.CreateSExt(Result, ConvertType(E->
getType()),
"sext");
2937 LHS = CGF.EmitComplexExpr(E->
getLHS());
2938 CETy = CTy->getElementType();
2940 LHS.first = Visit(E->
getLHS());
2941 LHS.second = llvm::Constant::getNullValue(LHS.first->getType());
2945 RHS = CGF.EmitComplexExpr(E->
getRHS());
2946 assert(CGF.getContext().hasSameUnqualifiedType(CETy,
2947 CTy->getElementType()) &&
2948 "The element types must always match.");
2951 RHS.first = Visit(E->
getRHS());
2952 RHS.second = llvm::Constant::getNullValue(RHS.first->getType());
2953 assert(CGF.getContext().hasSameUnqualifiedType(CETy, RHSTy) &&
2954 "The element types must always match.");
2957 Value *ResultR, *ResultI;
2959 ResultR =
Builder.CreateFCmp(FCmpOpc, LHS.first, RHS.first,
"cmp.r");
2960 ResultI =
Builder.CreateFCmp(FCmpOpc, LHS.second, RHS.second,
"cmp.i");
2964 ResultR =
Builder.CreateICmp(UICmpOpc, LHS.first, RHS.first,
"cmp.r");
2965 ResultI =
Builder.CreateICmp(UICmpOpc, LHS.second, RHS.second,
"cmp.i");
2969 Result =
Builder.CreateAnd(ResultR, ResultI,
"and.ri");
2972 "Complex comparison other than == or != ?");
2973 Result =
Builder.CreateOr(ResultR, ResultI,
"or.ri");
2977 return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->
getType(),
2981 Value *ScalarExprEmitter::VisitBinAssign(
const BinaryOperator *E) {
2982 bool Ignore = TestAndClearIgnoreResultAssign();
2989 std::tie(LHS, RHS) = CGF.EmitARCStoreStrong(E, Ignore);
2993 std::tie(LHS, RHS) = CGF.EmitARCStoreAutoreleasing(E);
2997 RHS = Visit(E->
getRHS());
2999 RHS = CGF.EmitARCStoreWeak(LHS.getAddress(), RHS, Ignore);
3007 RHS = Visit(E->
getRHS());
3014 if (LHS.isBitField())
3015 CGF.EmitStoreThroughBitfieldLValue(
RValue::get(RHS), LHS, &RHS);
3017 CGF.EmitStoreThroughLValue(
RValue::get(RHS), LHS);
3025 if (!CGF.getLangOpts().CPlusPlus)
3029 if (!LHS.isVolatileQualified())
3033 return EmitLoadOfLValue(LHS, E->
getExprLoc());
3036 Value *ScalarExprEmitter::VisitBinLAnd(
const BinaryOperator *E) {
3039 CGF.incrementProfileCounter(E);
3041 Value *LHS = Visit(E->
getLHS());
3042 Value *RHS = Visit(E->
getRHS());
3043 Value *Zero = llvm::ConstantAggregateZero::get(LHS->getType());
3044 if (LHS->getType()->isFPOrFPVectorTy()) {
3045 LHS =
Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, LHS, Zero,
"cmp");
3046 RHS =
Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, RHS, Zero,
"cmp");
3048 LHS =
Builder.CreateICmp(llvm::CmpInst::ICMP_NE, LHS, Zero,
"cmp");
3049 RHS =
Builder.CreateICmp(llvm::CmpInst::ICMP_NE, RHS, Zero,
"cmp");
3052 return Builder.CreateSExt(And, ConvertType(E->
getType()),
"sext");
3060 if (CGF.ConstantFoldsToSimpleInteger(E->
getLHS(), LHSCondVal)) {
3062 CGF.incrementProfileCounter(E);
3064 Value *RHSCond = CGF.EvaluateExprAsBool(E->
getRHS());
3066 return Builder.CreateZExtOrBitCast(RHSCond, ResTy,
"land.ext");
3070 if (!CGF.ContainsLabel(E->
getRHS()))
3071 return llvm::Constant::getNullValue(ResTy);
3074 llvm::BasicBlock *ContBlock = CGF.createBasicBlock(
"land.end");
3075 llvm::BasicBlock *RHSBlock = CGF.createBasicBlock(
"land.rhs");
3080 CGF.EmitBranchOnBoolExpr(E->
getLHS(), RHSBlock, ContBlock,
3081 CGF.getProfileCount(E->
getRHS()));
3088 for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock);
3090 PN->addIncoming(llvm::ConstantInt::getFalse(VMContext), *PI);
3093 CGF.EmitBlock(RHSBlock);
3094 CGF.incrementProfileCounter(E);
3095 Value *RHSCond = CGF.EvaluateExprAsBool(E->
getRHS());
3099 RHSBlock =
Builder.GetInsertBlock();
3105 CGF.EmitBlock(ContBlock);
3108 PN->addIncoming(RHSCond, RHSBlock);
3111 return Builder.CreateZExtOrBitCast(PN, ResTy,
"land.ext");
3117 CGF.incrementProfileCounter(E);
3119 Value *LHS = Visit(E->
getLHS());
3120 Value *RHS = Visit(E->
getRHS());
3121 Value *Zero = llvm::ConstantAggregateZero::get(LHS->getType());
3122 if (LHS->getType()->isFPOrFPVectorTy()) {
3123 LHS =
Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, LHS, Zero,
"cmp");
3124 RHS =
Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, RHS, Zero,
"cmp");
3126 LHS =
Builder.CreateICmp(llvm::CmpInst::ICMP_NE, LHS, Zero,
"cmp");
3127 RHS =
Builder.CreateICmp(llvm::CmpInst::ICMP_NE, RHS, Zero,
"cmp");
3129 Value *Or =
Builder.CreateOr(LHS, RHS);
3130 return Builder.CreateSExt(Or, ConvertType(E->
getType()),
"sext");
3138 if (CGF.ConstantFoldsToSimpleInteger(E->
getLHS(), LHSCondVal)) {
3140 CGF.incrementProfileCounter(E);
3142 Value *RHSCond = CGF.EvaluateExprAsBool(E->
getRHS());
3144 return Builder.CreateZExtOrBitCast(RHSCond, ResTy,
"lor.ext");
3148 if (!CGF.ContainsLabel(E->
getRHS()))
3149 return llvm::ConstantInt::get(ResTy, 1);
3152 llvm::BasicBlock *ContBlock = CGF.createBasicBlock(
"lor.end");
3153 llvm::BasicBlock *RHSBlock = CGF.createBasicBlock(
"lor.rhs");
3158 CGF.EmitBranchOnBoolExpr(E->
getLHS(), ContBlock, RHSBlock,
3159 CGF.getCurrentProfileCount() -
3160 CGF.getProfileCount(E->
getRHS()));
3167 for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock);
3169 PN->addIncoming(llvm::ConstantInt::getTrue(VMContext), *PI);
3174 CGF.EmitBlock(RHSBlock);
3175 CGF.incrementProfileCounter(E);
3176 Value *RHSCond = CGF.EvaluateExprAsBool(E->
getRHS());
3181 RHSBlock =
Builder.GetInsertBlock();
3185 CGF.EmitBlock(ContBlock);
3186 PN->addIncoming(RHSCond, RHSBlock);
3189 return Builder.CreateZExtOrBitCast(PN, ResTy,
"lor.ext");
3192 Value *ScalarExprEmitter::VisitBinComma(
const BinaryOperator *E) {
3193 CGF.EmitIgnoredExpr(E->
getLHS());
3194 CGF.EnsureInsertPoint();
3195 return Visit(E->
getRHS());
3220 Value *ScalarExprEmitter::
3222 TestAndClearIgnoreResultAssign();
3234 if (CGF.ConstantFoldsToSimpleInteger(condExpr, CondExprBool)) {
3235 Expr *live = lhsExpr, *dead = rhsExpr;
3236 if (!CondExprBool) std::swap(live, dead);
3239 if (!CGF.ContainsLabel(dead)) {
3241 CGF.incrementProfileCounter(E);
3242 Value *Result = Visit(live);
3248 Result = llvm::UndefValue::get(CGF.ConvertType(E->
getType()));
3256 if (CGF.getLangOpts().OpenCL
3258 CGF.incrementProfileCounter(E);
3260 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
3265 llvm::VectorType *vecTy = cast<llvm::VectorType>(condType);
3267 unsigned numElem = vecTy->getNumElements();
3268 llvm::Type *elemType = vecTy->getElementType();
3270 llvm::Value *zeroVec = llvm::Constant::getNullValue(vecTy);
3273 llvm::VectorType::get(elemType,
3281 bool wasCast =
false;
3282 llvm::VectorType *rhsVTy = cast<llvm::VectorType>(RHS->getType());
3283 if (rhsVTy->getElementType()->isFloatingPointTy()) {
3284 RHSTmp =
Builder.CreateBitCast(RHS, tmp2->getType());
3285 LHSTmp =
Builder.CreateBitCast(LHS, tmp->getType());
3293 tmp5 =
Builder.CreateBitCast(tmp5, RHS->getType());
3303 CGF.incrementProfileCounter(E);
3305 llvm::Value *CondV = CGF.EvaluateExprAsBool(condExpr);
3310 assert(!RHS &&
"LHS and RHS types must match");
3313 return Builder.CreateSelect(CondV, LHS, RHS,
"cond");
3316 llvm::BasicBlock *LHSBlock = CGF.createBasicBlock(
"cond.true");
3317 llvm::BasicBlock *RHSBlock = CGF.createBasicBlock(
"cond.false");
3318 llvm::BasicBlock *ContBlock = CGF.createBasicBlock(
"cond.end");
3321 CGF.EmitBranchOnBoolExpr(condExpr, LHSBlock, RHSBlock,
3322 CGF.getProfileCount(lhsExpr));
3324 CGF.EmitBlock(LHSBlock);
3325 CGF.incrementProfileCounter(E);
3327 Value *LHS = Visit(lhsExpr);
3330 LHSBlock =
Builder.GetInsertBlock();
3333 CGF.EmitBlock(RHSBlock);
3335 Value *RHS = Visit(rhsExpr);
3338 RHSBlock =
Builder.GetInsertBlock();
3339 CGF.EmitBlock(ContBlock);
3348 llvm::PHINode *PN =
Builder.CreatePHI(LHS->getType(), 2,
"cond");
3349 PN->addIncoming(LHS, LHSBlock);
3350 PN->addIncoming(RHS, RHSBlock);
3354 Value *ScalarExprEmitter::VisitChooseExpr(
ChooseExpr *E) {
3358 Value *ScalarExprEmitter::VisitVAArgExpr(
VAArgExpr *VE) {
3362 CGF.EmitVariablyModifiedType(Ty);
3365 Address ArgPtr = CGF.EmitVAArg(VE, ArgValue);
3377 if (ArgTy != Val->getType()) {
3378 if (ArgTy->isPointerTy() && !Val->getType()->isPointerTy())
3379 Val =
Builder.CreateIntToPtr(Val, ArgTy);
3381 Val =
Builder.CreateTrunc(Val, ArgTy);
3387 Value *ScalarExprEmitter::VisitBlockExpr(
const BlockExpr *block) {
3388 return CGF.EmitBlockLiteral(block);
3391 Value *ScalarExprEmitter::VisitAsTypeExpr(
AsTypeExpr *E) {
3392 Value *Src = CGF.EmitScalarExpr(E->
getSrcExpr());
3398 if (isa<llvm::VectorType>(DstTy) && isa<llvm::VectorType>(SrcTy)) {
3399 unsigned numElementsDst = cast<llvm::VectorType>(DstTy)->getNumElements();
3400 unsigned numElementsSrc = cast<llvm::VectorType>(SrcTy)->getNumElements();
3401 if ((numElementsDst == 3 && numElementsSrc == 4)
3402 || (numElementsDst == 4 && numElementsSrc == 3)) {
3412 if ((srcElemTy->isIntegerTy() && dstElemTy->isFloatTy())
3413 || (srcElemTy->isFloatTy() && dstElemTy->isIntegerTy())) {
3415 llvm::VectorType *newSrcTy = llvm::VectorType::get(dstElemTy,
3418 Src =
Builder.CreateBitCast(Src, newSrcTy,
"astypeCast");
3421 llvm::Value *UnV = llvm::UndefValue::get(Src->getType());
3424 Args.push_back(
Builder.getInt32(0));
3425 Args.push_back(
Builder.getInt32(1));
3426 Args.push_back(
Builder.getInt32(2));
3428 if (numElementsDst == 4)
3429 Args.push_back(llvm::UndefValue::get(CGF.Int32Ty));
3431 llvm::Constant *Mask = llvm::ConstantVector::get(Args);
3433 return Builder.CreateShuffleVector(Src, UnV, Mask,
"astype");
3437 return Builder.CreateBitCast(Src, DstTy,
"astype");
3440 Value *ScalarExprEmitter::VisitAtomicExpr(
AtomicExpr *E) {
3441 return CGF.EmitAtomicExpr(E).getScalarVal();
3452 "Invalid scalar expression to emit");
3454 return ScalarExprEmitter(*
this, IgnoreResultAssign)
3455 .Visit(const_cast<Expr *>(E));
3464 "Invalid scalar expression to emit");
3465 return ScalarExprEmitter(*this).EmitScalarConversion(Src, SrcTy, DstTy, Loc);
3475 "Invalid complex -> scalar conversion");
3476 return ScalarExprEmitter(*
this)
3477 .EmitComplexToScalarConversion(Src, SrcTy, DstTy, Loc);
3483 bool isInc,
bool isPre) {
3484 return ScalarExprEmitter(*this).EmitScalarPrePostIncDec(E, LV, isInc, isPre);
3507 ScalarExprEmitter Scalar(*
this);
3508 Value *Result =
nullptr;
3510 #define COMPOUND_OP(Op) \
3511 case BO_##Op##Assign: \
3512 return Scalar.EmitCompoundAssignLValue(E, &ScalarExprEmitter::Emit##Op, \
3548 llvm_unreachable(
"Not valid compound assignment operators");
3551 llvm_unreachable(
"Unhandled compound assignment operator");
Defines the clang::ASTContext interface.
unsigned getNumInits() const
CastKind getCastKind() const
The null pointer literal (C++11 [lex.nullptr])
CK_LValueToRValue - A conversion which causes the extraction of an r-value from the operand gl-value...
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
static BinOpInfo createBinOpInfoFromIncDec(const UnaryOperator *E, llvm::Value *InVal, bool IsInc)
bool isNullPtrType() const
bool isSignedOverflowDefined() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
llvm::Value * getPointer() const
unsigned getFieldCount() const
getFieldCount - Get the number of fields in the layout.
static Opcode getOpForCompoundAssignment(Opcode Opc)
QualType getType() const
Retrieves the type of the base class.
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
CompoundStmt * getSubStmt()
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
bool isOne() const
isOne - Test whether the quantity equals one.
static llvm::Constant * getAsInt32(llvm::ConstantInt *C, llvm::Type *I32Ty)
bool isArgumentType() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
TypeSourceInfo * getTypeSourceInfo() const
unsigned getPackLength() const
Retrieve the length of the parameter pack.
CK_ToUnion - The GCC cast-to-union extension.
Address getAddress() const
ParenExpr - This represents a parethesized expression, e.g.
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
CK_BaseToDerivedMemberPointer - Member pointer in base class to member pointer in derived class...
const Expr * getResultExpr() const
The generic selection's result expression.
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent...
CK_FloatingToIntegral - Floating point to integral.
bool isBooleanType() const
const LangOptions & getLangOpts() const
[ARC] Consumes a retainable object pointer that has just been produced, e.g.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
static Value * buildFMulAdd(llvm::BinaryOperator *MulOp, Value *Addend, const CodeGenFunction &CGF, CGBuilderTy &Builder, bool negMul, bool negAdd)
CK_IntegralToFloating - Integral to floating point.
Expr * getIndexExpr(unsigned Idx)
bool hadArrayRangeDesignator() const
CK_IntegralCast - A cast between integral types (other than to boolean).
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
CompoundLiteralExpr - [C99 6.5.2.5].
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
field_iterator field_begin() const
CK_Dynamic - A C++ dynamic_cast.
UnaryExprOrTypeTrait getKind() const
CK_Dependent - A conversion which cannot yet be analyzed because either the expression or target type...
unsigned getValue() const
A C++ throw-expression (C++ [except.throw]).
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, QualType IndexType, bool Accessed)
Emit a check that Base points into an array object, which we can access at index Index.
RecordDecl - Represents a struct/union/class.
An object to manage conditionally-evaluated expressions.
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
bool isVolatileQualified() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Converts between different integral complex types.
bool isReferenceType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Converting between two Objective-C object types, which can occur when performing reference binding to...
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
CK_FloatingCast - Casting between floating types of different size.
[ARC] Causes a value of block type to be copied to the heap, if it is not already there...
CK_VectorSplat - A conversion from an arithmetic type to a vector of that element type...
llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp, [NSNumber numberWithInt:42]];.
CK_NullToPointer - Null pointer constant to pointer, ObjC pointer, or block pointer.
CK_PointerToIntegral - Pointer to integral.
CK_IntegralToPointer - Integral to pointer.
bool isFPContractable() const
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Converts a floating point complex to bool by comparing against 0+0i.
Describes an C or C++ initializer list.
CK_IntegralToBoolean - Integral to boolean.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
static bool hasScalarEvaluationKind(QualType T)
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.
path_iterator path_begin()
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
llvm::PointerType * VoidPtrTy
A builtin binary operation expression such as "x + y" or "x <= y".
RecordDecl * getDecl() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
static Value * tryEmitFMulAdd(const BinOpInfo &op, const CodeGenFunction &CGF, CGBuilderTy &Builder, bool isSub=false)
ObjCStringLiteral, used for Objective-C string literals i.e.
static llvm::Constant * getMaskElt(llvm::ShuffleVectorInst *SVI, unsigned Idx, unsigned Off, llvm::Type *I32Ty)
Scope - A scope is a transient data structure that is used while parsing the program.
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...
Helper class for OffsetOfExpr.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
bool isExtVectorType() const
detail::InMemoryDirectory::const_iterator I
A default argument (C++ [dcl.fct.default]).
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
Checking the operand of a load. Must be suitably sized and aligned.
This object can be modified without requiring retains or releases.
Represents the this expression in C++.
field_iterator field_end() const
CK_AnyPointerToBlockPointerCast - Casting any non-block pointer to a block pointer.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource AlignSource=AlignmentSource::Type)
Sema - This implements semantic analysis and AST building for C.
static CharUnits One()
One - Construct a CharUnits quantity of one.
llvm::APInt getValue() const
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Causes a block literal to by copied to the heap and then autoreleased.
CastKind
CastKind - The kind of operation required for a conversion.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
const Expr * getExpr() const
Get the initialization expression that will be used.
Represents a call to the builtin function __builtin_va_arg.
ID
Defines the set of possible language-specific address spaces.
CK_FunctionToPointerDecay - Function to pointer decay.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Converts between different floating point complex types.
bool isRealFloatingType() const
Floating point categories.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
const ObjCMethodDecl * getMethodDecl() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
llvm::Value * getPointer() const
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
CK_PointerToBoolean - Pointer to boolean conversion.
Allow any unmodeled side effect.
Converts an integral complex to an integral real of the source's element type by discarding the imagi...
CK_BitCast - A conversion which causes a bit pattern of one type to be reinterpreted as a bit pattern...
bool isAnyComplexType() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type, where the destination type is an LLVM scalar type.
SourceLocation getExprLoc() const LLVM_READONLY
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
bool isFloatingType() const
ObjCSelectorExpr used for @selector in Objective-C.
Represents an expression that computes the length of a parameter pack.
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
An RAII object to record that we're evaluating a statement expression.
Expr * getSubExpr() const
CK_ConstructorConversion - Conversion by constructor.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
An expression that sends a message to the given Objective-C object or class.
unsigned getNumComponents() const
Converts from an integral complex to a floating complex.
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep)
Creates clause with a list of variables VL and a linear step Step.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a GCC generic vector type.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
Represents a reference to a non-type template parameter that has been substituted with a template arg...
The scope of a CXXDefaultInitExpr.
QualType getElementType() const
QualType getComputationLHSType() const
The result type of a method or function.
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
CK_ArrayToPointerDecay - Array to pointer decay.
QualType getComputationResultType() const
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
The l-value was considered opaque, so the alignment was determined from a type.
CK_CPointerToObjCPointerCast - Casting a C pointer kind to an Objective-C pointer.
There is no lifetime qualification on this type.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Assigning into this object requires the old value to be released and the new value to be retained...
A field in a dependent type, known only by its name.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
CK_UserDefinedConversion - Conversion using a user defined type conversion function.
ASTContext & getContext() const
Encodes a location in the source.
CharUnits getPointerAlign() const
bool hasIntegerRepresentation() const
Determine whether this type has an integer representation of some sort, e.g., it is an integer type o...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
const TemplateArgument * iterator
SourceLocation getExprLoc() const LLVM_READONLY
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
CK_NullToMemberPointer - Null pointer constant to member pointer.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
A scoped helper to set the current debug location to the specified location or preferred location of ...
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
CK_ReinterpretMemberPointer - Reinterpret a member pointer as a different kind of member pointer...
bool isCompoundAssignmentOp() const
CK_DerivedToBase - A conversion from a C++ class pointer to a base class pointer. ...
SanitizerSet SanOpts
Sanitizers enabled for this function.
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>.
ObjCProtocolExpr used for protocol expression in Objective-C.
const CodeGenOptions & getCodeGenOpts() const
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
Converts from an integral real to an integral complex whose element type matches the source...
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
QualType getReturnType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isVectorType() const
An expression trait intrinsic.
uint64_t getValue() const
Assigning into this object requires a lifetime extension.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
ObjCBoxedExpr - used for generalized expression boxing.
QualType getType() const
Return the type wrapped by this type source info.
const OffsetOfNode & getComponent(unsigned Idx) const
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getPointeeType() const
CompoundAssignOperator - For compound assignments (e.g.
Represents a C11 generic selection.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
AddrLabelExpr - The GNU address of label extension, representing &&label.
Converts a floating point complex to floating point real of the source's element type.
Expr * getReplacement() const
SourceLocation getExprLoc() const LLVM_READONLY
static const Type * getElementType(const Expr *BaseExpr)
const Expr * getExpr() const
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Converts an integral complex to bool by comparing against 0+0i.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
CK_BaseToDerived - A conversion from a C++ class pointer/reference to a derived class pointer/referen...
static llvm::Intrinsic::ID GetIntrinsic(IntrinsicType IT, BuiltinType::Kind ElemKind)
static Value * emitPointerArithmetic(CodeGenFunction &CGF, const BinOpInfo &op, bool isSubtraction)
Emit pointer + index arithmetic.
Checking the destination of a store. Must be suitably sized and aligned.
CK_BlockPointerToObjCPointerCast - Casting a block pointer to an ObjC pointer.
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
A conversion of a floating point real to a floating point complex of the original type...
CK_MemberPointerToBoolean - Member pointer to boolean.
ExplicitCastExpr - An explicit cast written in the source code.
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).
llvm::APFloat getValue() const
[ARC] Reclaim a retainable object pointer object that may have been produced and autoreleased as part...
const VariableArrayType * getAsVariableArrayType(QualType T) const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
#define VISITCOMP(CODE, UI, SI, FP)
Represents a pointer to an Objective C object.
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
const T * getAs() const
Member-template getAs<specific type>'.
Checking the operand of a static_cast to a derived pointer type.
Expr * getFalseExpr() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
QualType getCanonicalType() const
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
An implicit indirection through a C++ base class, when the field found is in a base class...
[ARC] Produces a retainable object pointer so that it may be consumed, e.g.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
bool isFunctionType() const
ExtVectorType - Extended vector type.
CK_LValueBitCast - A conversion which reinterprets the address of an l-value as an l-value of a diffe...
Converts from T to _Atomic(T).
Converts from a floating complex to an integral complex.
SourceLocation getExprLoc() const LLVM_READONLY
LabelDecl * getLabel() const
CK_UncheckedDerivedToBase - A conversion from a C++ class pointer/reference to a base class that can ...
ObjCIvarRefExpr - A reference to an ObjC instance variable.
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
A use of a default initializer in a constructor or in aggregate initialization.
llvm::IntegerType * PtrDiffTy
Reading or writing from this object requires a barrier call.
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.
llvm::Type * ConvertType(QualType T)
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
FieldDecl * getField() const
For a field offsetof node, returns the field.
This class is used for builtin types like 'int'.
Converts from _Atomic(T) to T.
std::pair< llvm::Value *, QualType > getVLASize(const VariableArrayType *vla)
getVLASize - Returns an LLVM value that corresponds to the size, in non-variably-sized elements...
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
CK_NoOp - A conversion which does not affect the type other than (possibly) adding qualifiers...
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
CK_DerivedToBaseMemberPointer - Member pointer in derived class to member pointer in base class...
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
const Expr * getInit(unsigned Init) const
LValue - This represents an lvalue references.
A boolean literal, per ([C++ lex.bool] Boolean literals).
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Represents a C array with a specified size that is not an integer-constant-expression.
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
CK_ToVoid - Cast to void, discarding the computed value.
static bool isCheapEnoughToEvaluateUnconditionally(const Expr *E, CodeGenFunction &CGF)
isCheapEnoughToEvaluateUnconditionally - Return true if the specified expression is cheap enough and ...
Represents an implicitly-generated value initialization of an object of a given type.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Kind getKind() const
Determine what kind of offsetof node this is.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
CK_FloatingToBoolean - Floating point to boolean.