38#include "llvm/ADT/STLExtras.h"
39#include "llvm/ADT/ScopeExit.h"
40#include "llvm/ADT/StringExtras.h"
41#include "llvm/IR/DataLayout.h"
42#include "llvm/IR/Intrinsics.h"
43#include "llvm/IR/LLVMContext.h"
44#include "llvm/IR/MDBuilder.h"
45#include "llvm/IR/MatrixBuilder.h"
46#include "llvm/Support/ConvertUTF.h"
47#include "llvm/Support/Endian.h"
48#include "llvm/Support/MathExtras.h"
49#include "llvm/Support/Path.h"
50#include "llvm/Support/xxhash.h"
51#include "llvm/Transforms/Utils/SanitizerStats.h"
64 "ubsan-guard-checks", llvm::cl::Optional,
65 llvm::cl::desc(
"Guard UBSAN checks with `llvm.allow.ubsan.check()`."));
91#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
92 case SanitizerHandler::Enum: \
97 llvm_unreachable(
"unhandled switch case");
105 llvm::Value *ArraySize) {
113 llvm::Value *ArraySize) {
123 llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
140 llvm::Value *ArraySize,
144 *AllocaAddr = Alloca;
145 return MaybeCastStackAddressSpace(Alloca, DestLangAS, ArraySize);
153 llvm::Value *ArraySize) {
154 llvm::AllocaInst *Alloca;
156 Alloca =
Builder.CreateAlloca(Ty, ArraySize, Name);
159 new llvm::AllocaInst(Ty,
CGM.getDataLayout().getAllocaAddrSpace(),
161 if (
SanOpts.Mask & SanitizerKind::Address) {
162 Alloca->addAnnotationMetadata({
"alloca_name_altered", Name.str()});
165 Allocas->Add(Alloca);
200 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),
201 ArrayTy->getNumElements());
224 PGO->setCurrentStmt(E);
227 return CGM.getCXXABI().EmitMemberPointerIsNotNull(*
this, MemPtr, MPT);
250 if (
const auto *CondOp = dyn_cast<AbstractConditionalOperator>(
273 if (!ignoreResult && aggSlot.
isIgnored())
278 llvm_unreachable(
"bad evaluation kind");
320 llvm_unreachable(
"bad evaluation kind");
343 llvm_unreachable(
"bad evaluation kind");
383 bool Precise = isa_and_nonnull<VarDecl>(VD) &&
384 VD->
hasAttr<ObjCPreciseLifetimeAttr>();
405 llvm_unreachable(
"temporary cannot have dynamic storage duration");
407 llvm_unreachable(
"unknown storage duration");
417 if (
const auto *ClassDecl =
421 ReferenceTemporaryDtor = ClassDecl->getDestructor();
423 if (!ReferenceTemporaryDtor)
426 llvm::FunctionCallee CleanupFn;
427 llvm::Constant *CleanupArg;
433 CleanupArg = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
450 llvm_unreachable(
"temporary cannot have dynamic storage duration");
473 auto *GV =
new llvm::GlobalVariable(
475 llvm::GlobalValue::PrivateLinkage,
Init,
".ref.tmp",
nullptr,
476 llvm::GlobalValue::NotThreadLocal,
480 llvm::Constant *
C = GV;
482 C = TCG.performAddrSpaceCast(
484 llvm::PointerType::get(
488 return RawAddress(
C, GV->getValueType(), alignment);
497 llvm_unreachable(
"temporary can't have dynamic storage duration");
499 llvm_unreachable(
"unknown storage duration");
513 "Reference should never be pseudo-strong!");
521 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object.getPointer())) {
523 Object = Object.withElementType(Ty);
531 if (Var->hasInitializer())
534 Var->setInitializer(
CGM.EmitNullConstant(E->
getType()));
540 default: llvm_unreachable(
"expected scalar or aggregate expression");
563 for (
const auto &Ignored : CommaLHSs)
566 if (
const auto *opaque = dyn_cast<OpaqueValueExpr>(E)) {
567 if (opaque->getType()->isRecordType()) {
568 assert(Adjustments.empty());
576 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(
577 Object.getPointer()->stripPointerCasts())) {
579 Object = Object.withElementType(TemporaryType);
583 if (!Var->hasInitializer()) {
584 Var->setInitializer(
CGM.EmitNullConstant(E->
getType()));
589 Object.getAlignment());
605 if (!ShouldEmitLifetimeMarkers)
616 CGBuilderTy::InsertPoint OldIP;
618 ((!
SanOpts.has(SanitizerKind::HWAddress) &&
619 !
SanOpts.has(SanitizerKind::Memory) &&
620 !
CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) ||
622 OldConditional = OutermostConditional;
623 OutermostConditional =
nullptr;
627 Builder.restoreIP(CGBuilderTy::InsertPoint(
628 Block, llvm::BasicBlock::iterator(
Block->back())));
635 if (OldConditional) {
636 OutermostConditional = OldConditional;
653 switch (Adjustment.Kind) {
657 Adjustment.DerivedToBase.BasePath->path_begin(),
658 Adjustment.DerivedToBase.BasePath->path_end(),
666 "materialized temporary field is not a simple lvalue");
674 E, Object, Ptr, Adjustment.Ptr.MPT,
true);
707 const llvm::Constant *Elts) {
715 Builder.CreateMul(Ptr, Builder.getInt64(0xbf58476d1ce4e5b9u));
717 Builder.CreateXor(A0, Builder.CreateLShr(A0, Builder.getInt64(31)));
718 return Builder.CreateXor(Acc, A1);
735 return SanOpts.has(SanitizerKind::Null) ||
736 SanOpts.has(SanitizerKind::Alignment) ||
737 SanOpts.has(SanitizerKind::ObjectSize) ||
738 SanOpts.has(SanitizerKind::Vptr);
745 llvm::Value *ArraySize) {
752 if (Ptr->getType()->getPointerAddressSpace())
763 auto PtrToAlloca = dyn_cast<llvm::AllocaInst>(Ptr->stripPointerCasts());
765 llvm::Value *IsNonNull =
nullptr;
766 bool IsGuaranteedNonNull =
767 SkippedChecks.
has(SanitizerKind::Null) || PtrToAlloca;
769 llvm::BasicBlock *Done =
nullptr;
770 bool DoneViaNullSanitize =
false;
773 auto CheckHandler = SanitizerHandler::TypeMismatch;
775 {SanitizerKind::SO_Null,
776 SanitizerKind::SO_ObjectSize,
777 SanitizerKind::SO_Alignment},
785 if ((
SanOpts.has(SanitizerKind::Null) || AllowNullPointers) &&
786 !IsGuaranteedNonNull) {
788 IsNonNull =
Builder.CreateIsNotNull(Ptr);
792 IsGuaranteedNonNull = IsNonNull ==
True;
795 if (!IsGuaranteedNonNull) {
796 if (AllowNullPointers) {
800 DoneViaNullSanitize =
true;
802 Builder.CreateCondBr(IsNonNull, Rest, Done);
805 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::SO_Null));
810 if (
SanOpts.has(SanitizerKind::ObjectSize) &&
811 !SkippedChecks.
has(SanitizerKind::ObjectSize) &&
813 uint64_t TySize =
CGM.getMinimumObjectSize(Ty).getQuantity();
814 llvm::Value *Size = llvm::ConstantInt::get(
IntPtrTy, TySize);
816 Size =
Builder.CreateMul(Size, ArraySize);
819 llvm::Constant *ConstantSize = dyn_cast<llvm::Constant>(Size);
820 if (!ConstantSize || !ConstantSize->isNullValue()) {
827 llvm::Function *F =
CGM.getIntrinsic(llvm::Intrinsic::objectsize, Tys);
829 llvm::Value *NullIsUnknown =
Builder.getFalse();
830 llvm::Value *Dynamic =
Builder.getFalse();
831 llvm::Value *LargeEnough =
Builder.CreateICmpUGE(
832 Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic}), Size);
834 std::make_pair(LargeEnough, SanitizerKind::SO_ObjectSize));
838 llvm::MaybeAlign AlignVal;
839 llvm::Value *PtrAsInt =
nullptr;
841 if (
SanOpts.has(SanitizerKind::Alignment) &&
842 !SkippedChecks.
has(SanitizerKind::Alignment)) {
845 AlignVal =
CGM.getNaturalTypeAlignment(Ty,
nullptr,
nullptr,
850 if (AlignVal && *AlignVal > llvm::Align(1) &&
851 (!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {
853 llvm::Value *Align =
Builder.CreateAnd(
854 PtrAsInt, llvm::ConstantInt::get(
IntPtrTy, AlignVal->value() - 1));
855 llvm::Value *Aligned =
859 std::make_pair(Aligned, SanitizerKind::SO_Alignment));
863 if (Checks.size() > 0) {
864 llvm::Constant *StaticData[] = {
866 llvm::ConstantInt::get(
Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),
867 llvm::ConstantInt::get(
Int8Ty, TCK)};
868 EmitCheck(Checks, CheckHandler, StaticData, PtrAsInt ? PtrAsInt : Ptr);
880 if (
SanOpts.has(SanitizerKind::Vptr) &&
883 SanitizerHandler::DynamicTypeCacheMiss);
887 if (!IsGuaranteedNonNull) {
889 IsNonNull =
Builder.CreateIsNotNull(Ptr);
893 Builder.CreateCondBr(IsNonNull, VptrNotNull, Done);
899 llvm::raw_svector_ostream Out(MangledName);
904 if (!
CGM.getContext().getNoSanitizeList().containsType(SanitizerKind::Vptr,
907 llvm::Value *TypeHash =
908 llvm::ConstantInt::get(
Int64Ty, xxh3_64bits(Out.str()));
922 const int CacheSize = 128;
923 llvm::Type *HashTable = llvm::ArrayType::get(
IntPtrTy, CacheSize);
924 llvm::Value *
Cache =
CGM.CreateRuntimeVariable(HashTable,
925 "__ubsan_vptr_type_cache");
926 llvm::Value *Slot =
Builder.CreateAnd(Hash,
929 llvm::Value *Indices[] = {
Builder.getInt32(0), Slot };
930 llvm::Value *CacheVal =
Builder.CreateAlignedLoad(
938 llvm::Value *EqualHash =
Builder.CreateICmpEQ(CacheVal, Hash);
939 llvm::Constant *StaticData[] = {
943 llvm::ConstantInt::get(
Int8Ty, TCK)
945 llvm::Value *DynamicData[] = { Ptr, Hash };
946 EmitCheck(std::make_pair(EqualHash, SanitizerKind::SO_Vptr),
947 SanitizerHandler::DynamicTypeCacheMiss, StaticData,
955 {DoneViaNullSanitize ? SanitizerKind::SO_Null : SanitizerKind::SO_Vptr},
956 DoneViaNullSanitize ? SanitizerHandler::TypeMismatch
957 : SanitizerHandler::DynamicTypeCacheMiss);
966 uint64_t EltSize =
C.getTypeSizeInChars(EltTy).getQuantity();
974 auto *ParamDecl = dyn_cast<ParmVarDecl>(ArrayDeclRef->getDecl());
978 auto *POSAttr = ParamDecl->getAttr<PassObjectSizeAttr>();
983 int POSType = POSAttr->getType();
984 if (POSType != 0 && POSType != 1)
988 auto PassedSizeIt = SizeArguments.find(ParamDecl);
989 if (PassedSizeIt == SizeArguments.end())
993 assert(LocalDeclMap.count(PassedSizeDecl) &&
"Passed size not loadable");
994 Address AddrOfSize = LocalDeclMap.find(PassedSizeDecl)->second;
997 llvm::Value *SizeOfElement =
998 llvm::ConstantInt::get(SizeInBytes->getType(), EltSize);
999 return Builder.CreateUDiv(SizeInBytes, SizeOfElement);
1008 StrictFlexArraysLevel) {
1011 IndexedType =
Base->getType();
1012 return CGF.
Builder.getInt32(VT->getNumElements());
1017 if (
const auto *CE = dyn_cast<CastExpr>(
Base)) {
1018 if (CE->getCastKind() == CK_ArrayToPointerDecay &&
1019 !CE->getSubExpr()->isFlexibleArrayMemberLike(CGF.
getContext(),
1020 StrictFlexArraysLevel)) {
1023 IndexedType = CE->getSubExpr()->getType();
1025 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
1026 return CGF.
Builder.getInt(CAT->getSize());
1028 if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
1036 QualType EltTy{
Base->getType()->getPointeeOrArrayElementType(), 0};
1038 IndexedType =
Base->getType();
1063class StructAccessBase
1064 :
public ConstStmtVisitor<StructAccessBase, const Expr *> {
1065 const RecordDecl *ExpectedRD;
1067 bool IsExpectedRecordDecl(
const Expr *E)
const {
1075 StructAccessBase(
const RecordDecl *ExpectedRD) : ExpectedRD(ExpectedRD) {}
1094 const Expr *Visit(
const Expr *E) {
1095 return ConstStmtVisitor<StructAccessBase, const Expr *>::Visit(E);
1098 const Expr *VisitStmt(
const Stmt *S) {
return nullptr; }
1113 const Expr *VisitDeclRefExpr(
const DeclRefExpr *E) {
1114 return IsExpectedRecordDecl(E) ? E :
nullptr;
1116 const Expr *VisitMemberExpr(
const MemberExpr *E) {
1117 if (IsExpectedRecordDecl(E) && E->
isArrow())
1119 const Expr *Res = Visit(E->
getBase());
1120 return !Res && IsExpectedRecordDecl(E) ? E : Res;
1122 const Expr *VisitCompoundLiteralExpr(
const CompoundLiteralExpr *E) {
1123 return IsExpectedRecordDecl(E) ? E :
nullptr;
1125 const Expr *VisitCallExpr(
const CallExpr *E) {
1126 return IsExpectedRecordDecl(E) ? E :
nullptr;
1129 const Expr *VisitArraySubscriptExpr(
const ArraySubscriptExpr *E) {
1130 if (IsExpectedRecordDecl(E))
1134 const Expr *VisitCastExpr(
const CastExpr *E) {
1136 return IsExpectedRecordDecl(E) ? E :
nullptr;
1139 const Expr *VisitParenExpr(
const ParenExpr *E) {
1142 const Expr *VisitUnaryAddrOf(
const UnaryOperator *E) {
1145 const Expr *VisitUnaryDeref(
const UnaryOperator *E) {
1158 int64_t FieldNo = -1;
1167 Indices.emplace_back(CGF.
Builder.getInt32(FieldNo));
1176 Indices.emplace_back(CGF.
Builder.getInt32(FieldNo));
1190 const Expr *StructBase = StructAccessBase(RD).Visit(
Base);
1194 llvm::Value *Res =
nullptr;
1199 Res =
Addr.emitRawPointer(*
this);
1200 }
else if (StructBase->
isLValue()) {
1203 Res =
Addr.emitRawPointer(*
this);
1210 if (Indices.empty())
1213 Indices.push_back(
Builder.getInt32(0));
1237 llvm::Value *Index,
QualType IndexType,
1239 assert(
SanOpts.has(SanitizerKind::ArrayBounds) &&
1240 "should not be called unless adding bounds checks");
1244 llvm::Value *Bound =
1253 QualType IndexedType,
bool Accessed) {
1257 auto CheckKind = SanitizerKind::SO_ArrayBounds;
1258 auto CheckHandler = SanitizerHandler::OutOfBounds;
1262 llvm::Value *IndexVal =
Builder.CreateIntCast(Index,
SizeTy, IndexSigned);
1263 llvm::Value *BoundVal =
Builder.CreateIntCast(Bound,
SizeTy,
false);
1265 llvm::Constant *StaticData[] = {
1270 llvm::Value *Check = Accessed ?
Builder.CreateICmpULT(IndexVal, BoundVal)
1271 :
Builder.CreateICmpULE(IndexVal, BoundVal);
1272 EmitCheck(std::make_pair(Check, CheckKind), CheckHandler, StaticData, Index);
1277 bool isInc,
bool isPre) {
1280 llvm::Value *NextVal;
1282 uint64_t AmountVal = isInc ? 1 : -1;
1283 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
1286 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1289 llvm::APFloat FVal(
getContext().getFloatTypeSemantics(ElemTy), 1);
1295 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1303 CGM.getOpenMPRuntime().checkAndEmitLastprivateConditional(*
this,
1308 return isPre ? IncVal : InVal;
1318 DI->EmitExplicitCastType(E->
getType());
1329 if (
auto *constantIdx = dyn_cast<llvm::ConstantInt>(idx)) {
1330 CharUnits offset = constantIdx->getZExtValue() * eltSize;
1344 assert(BO->
isAdditiveOp() &&
"Expect an addition or subtraction.");
1347 bool isSubtraction = BO->
getOpcode() == BO_Sub;
1350 llvm::Value *
index =
nullptr;
1354 std::swap(pointerOperand, indexOperand);
1366 BO, pointerOperand, pointer, indexOperand,
index, isSubtraction);
1373 nullptr, IsKnownNonNull);
1386 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
1387 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(CE))
1390 switch (CE->getCastKind()) {
1394 case CK_AddressSpaceConversion:
1395 if (
auto PtrTy = CE->getSubExpr()->getType()->getAs<
PointerType>()) {
1396 if (PtrTy->getPointeeType()->isVoidType())
1402 CE->getSubExpr(), &InnerBaseInfo, &InnerTBAAInfo, IsKnownNonNull);
1403 if (BaseInfo) *BaseInfo = InnerBaseInfo;
1404 if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
1410 E->
getType(), &TargetTypeBaseInfo, &TargetTypeTBAAInfo);
1418 BaseInfo->mergeForCast(TargetTypeBaseInfo);
1419 Addr.setAlignment(Align);
1423 if (CGF.
SanOpts.
has(SanitizerKind::CFIUnrelatedCast) &&
1424 CE->getCastKind() == CK_BitCast) {
1432 llvm::Type *ElemTy =
1434 Addr =
Addr.withElementType(ElemTy);
1435 if (CE->getCastKind() == CK_AddressSpaceConversion)
1445 case CK_ArrayToPointerDecay:
1449 case CK_UncheckedDerivedToBase:
1450 case CK_DerivedToBase: {
1457 CE->getSubExpr(), BaseInfo,
nullptr,
1459 CE->getCastKind() == CK_UncheckedDerivedToBase));
1460 auto Derived = CE->getSubExpr()->
getType()->getPointeeCXXRecordDecl();
1462 Addr, Derived, CE->path_begin(), CE->path_end(),
1475 if (UO->getOpcode() == UO_AddrOf) {
1476 LValue LV = CGF.
EmitLValue(UO->getSubExpr(), IsKnownNonNull);
1477 if (BaseInfo) *BaseInfo = LV.getBaseInfo();
1478 if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();
1479 return LV.getAddress();
1484 if (
auto *
Call = dyn_cast<CallExpr>(E)) {
1485 switch (
Call->getBuiltinCallee()) {
1488 case Builtin::BIaddressof:
1489 case Builtin::BI__addressof:
1490 case Builtin::BI__builtin_addressof: {
1492 if (BaseInfo) *BaseInfo = LV.getBaseInfo();
1493 if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();
1494 return LV.getAddress();
1500 if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
1501 if (BO->isAdditiveOp())
1510 true, BaseInfo, TBAAInfo, IsKnownNonNull);
1520 if (IsKnownNonNull && !
Addr.isKnownNonNull())
1521 Addr.setKnownNonNull();
1528 return CGM.getCXXABI().EmitMemberPointerIsNotNull(*
this,
V, MPT);
1529 return Builder.CreateICmpNE(
V, llvm::Constant::getNullValue(
V->getType()));
1540 llvm::Value *
U = llvm::UndefValue::get(EltTy);
1555 llvm_unreachable(
"bad evaluation kind");
1580 if (
const auto *CE = dyn_cast<CastExpr>(
Base)) {
1581 Base = CE->getSubExpr();
1582 }
else if (
const auto *PE = dyn_cast<ParenExpr>(
Base)) {
1583 Base = PE->getSubExpr();
1584 }
else if (
const auto *UO = dyn_cast<UnaryOperator>(
Base)) {
1585 if (UO->getOpcode() == UO_Extension)
1586 Base = UO->getSubExpr();
1604 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
1607 SkippedChecks.
set(SanitizerKind::Alignment,
true);
1609 SkippedChecks.
set(SanitizerKind::Null,
true);
1636 CGM.runWithSufficientStackSpace(
1637 E->
getExprLoc(), [&] { LV = EmitLValueHelper(E, IsKnownNonNull); });
1649 return cast<CallExpr>(SE)->getCallReturnType(Ctx)->getPointeeType();
1652LValue CodeGenFunction::EmitLValueHelper(
const Expr *E,
1654 ApplyDebugLocation DL(*
this, E);
1658 case Expr::ObjCPropertyRefExprClass:
1659 llvm_unreachable(
"cannot emit a property reference directly");
1661 case Expr::ObjCSelectorExprClass:
1663 case Expr::ObjCIsaExprClass:
1665 case Expr::BinaryOperatorClass:
1667 case Expr::CompoundAssignOperatorClass: {
1669 if (
const AtomicType *AT = Ty->
getAs<AtomicType>())
1670 Ty = AT->getValueType();
1675 case Expr::CallExprClass:
1676 case Expr::CXXMemberCallExprClass:
1677 case Expr::CXXOperatorCallExprClass:
1678 case Expr::UserDefinedLiteralClass:
1680 case Expr::CXXRewrittenBinaryOperatorClass:
1683 case Expr::VAArgExprClass:
1685 case Expr::DeclRefExprClass:
1687 case Expr::ConstantExprClass: {
1689 if (llvm::Value *
Result = ConstantEmitter(*this).tryEmitConstantExpr(CE)) {
1695 case Expr::ParenExprClass:
1697 case Expr::GenericSelectionExprClass:
1700 case Expr::PredefinedExprClass:
1702 case Expr::StringLiteralClass:
1704 case Expr::ObjCEncodeExprClass:
1706 case Expr::PseudoObjectExprClass:
1708 case Expr::InitListExprClass:
1710 case Expr::CXXTemporaryObjectExprClass:
1711 case Expr::CXXConstructExprClass:
1713 case Expr::CXXBindTemporaryExprClass:
1715 case Expr::CXXUuidofExprClass:
1717 case Expr::LambdaExprClass:
1720 case Expr::ExprWithCleanupsClass: {
1723 LValue LV =
EmitLValue(cleanups->getSubExpr(), IsKnownNonNull);
1724 if (LV.isSimple()) {
1727 Address
Addr = LV.getAddress();
1728 llvm::Value *
V =
Addr.getBasePointer();
1729 Scope.ForceCleanup({&
V});
1730 Addr.replaceBasePointer(
V);
1732 LV.getBaseInfo(), LV.getTBAAInfo());
1739 case Expr::CXXDefaultArgExprClass: {
1742 return EmitLValue(DAE->getExpr(), IsKnownNonNull);
1744 case Expr::CXXDefaultInitExprClass: {
1747 return EmitLValue(DIE->getExpr(), IsKnownNonNull);
1749 case Expr::CXXTypeidExprClass:
1752 case Expr::ObjCMessageExprClass:
1754 case Expr::ObjCIvarRefExprClass:
1756 case Expr::StmtExprClass:
1758 case Expr::UnaryOperatorClass:
1760 case Expr::ArraySubscriptExprClass:
1762 case Expr::MatrixSubscriptExprClass:
1764 case Expr::ArraySectionExprClass:
1766 case Expr::ExtVectorElementExprClass:
1768 case Expr::CXXThisExprClass:
1770 case Expr::MemberExprClass:
1772 case Expr::CompoundLiteralExprClass:
1774 case Expr::ConditionalOperatorClass:
1776 case Expr::BinaryConditionalOperatorClass:
1778 case Expr::ChooseExprClass:
1780 case Expr::OpaqueValueExprClass:
1782 case Expr::SubstNonTypeTemplateParmExprClass:
1785 case Expr::ImplicitCastExprClass:
1786 case Expr::CStyleCastExprClass:
1787 case Expr::CXXFunctionalCastExprClass:
1788 case Expr::CXXStaticCastExprClass:
1789 case Expr::CXXDynamicCastExprClass:
1790 case Expr::CXXReinterpretCastExprClass:
1791 case Expr::CXXConstCastExprClass:
1792 case Expr::CXXAddrspaceCastExprClass:
1793 case Expr::ObjCBridgedCastExprClass:
1796 case Expr::MaterializeTemporaryExprClass:
1799 case Expr::CoawaitExprClass:
1801 case Expr::CoyieldExprClass:
1803 case Expr::PackIndexingExprClass:
1805 case Expr::HLSLOutArgExprClass:
1806 llvm_unreachable(
"cannot emit a HLSL out argument directly");
1813 assert(
type.isCanonical());
1814 assert(!
type->isReferenceType());
1822 if (
const auto *RT = dyn_cast<RecordType>(
type))
1823 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getOriginalDecl())) {
1824 RD = RD->getDefinitionOrSelf();
1825 if (RD->hasMutableFields() || !RD->isTrivial())
1847 if (
const auto *ref = dyn_cast<ReferenceType>(
type)) {
1871 }
else if (
const auto *var = dyn_cast<VarDecl>(
Value)) {
1881 bool resultIsReference;
1887 resultIsReference =
false;
1893 resultIsReference =
true;
1914 auto *MD = dyn_cast_or_null<CXXMethodDecl>(
CurCodeDecl);
1915 if (
isLambdaMethod(MD) && MD->getOverloadedOperator() == OO_Call) {
1918 if (
const VarDecl *VD = dyn_cast<const VarDecl>(D)) {
1919 if (!VD->hasAttr<CUDADeviceAttr>()) {
1942 if (resultIsReference)
1969 assert(Constant &&
"not a constant");
1985 llvm::APInt &
Min, llvm::APInt &End,
1986 bool StrictEnums,
bool IsBool) {
1988 bool IsRegularCPlusPlusEnum =
1989 CGF.
getLangOpts().CPlusPlus && StrictEnums && ED && !ED->isFixed();
1990 if (!IsBool && !IsRegularCPlusPlusEnum)
1997 ED->getValueRange(End,
Min);
2002llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(QualType Ty) {
2003 llvm::APInt
Min, End;
2009 return MDHelper.createRange(
Min, End);
2017 }
else if (
CGM.getCodeGenOpts().OptimizationLevel > 0) {
2018 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) {
2019 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
2020 Load->setMetadata(llvm::LLVMContext::MD_noundef,
2021 llvm::MDNode::get(
CGM.getLLVMContext(), {}));
2028 bool HasBoolCheck =
SanOpts.has(SanitizerKind::Bool);
2029 bool HasEnumCheck =
SanOpts.has(SanitizerKind::Enum);
2030 if (!HasBoolCheck && !HasEnumCheck)
2035 bool NeedsBoolCheck = HasBoolCheck && IsBool;
2037 if (!NeedsBoolCheck && !NeedsEnumCheck)
2047 if (NeedsEnumCheck &&
2048 getContext().isTypeIgnoredBySanitizer(SanitizerKind::Enum, Ty))
2051 llvm::APInt
Min, End;
2056 NeedsEnumCheck ? SanitizerKind::SO_Enum : SanitizerKind::SO_Bool;
2059 auto CheckHandler = SanitizerHandler::LoadInvalidValue;
2064 Check =
Builder.CreateICmpULE(
Value, llvm::ConstantInt::get(Ctx, End));
2066 llvm::Value *Upper =
2067 Builder.CreateICmpSLE(
Value, llvm::ConstantInt::get(Ctx, End));
2068 llvm::Value *Lower =
2070 Check =
Builder.CreateAnd(Upper, Lower);
2074 EmitCheck(std::make_pair(Check, Kind), CheckHandler, StaticArgs,
Value);
2083 bool isNontemporal) {
2084 if (
auto *GV = dyn_cast<llvm::GlobalValue>(
Addr.getBasePointer()))
2085 if (GV->isThreadLocal())
2091 if (ClangVecTy->isPackedVectorBoolType(
getContext())) {
2093 unsigned ValNumElems =
2096 auto *RawIntV =
Builder.CreateLoad(
Addr, Volatile,
"load_bits");
2097 const auto *RawIntTy = RawIntV->getType();
2098 assert(RawIntTy->isIntegerTy() &&
"compressed iN storage for bitvectors");
2100 auto *PaddedVecTy = llvm::FixedVectorType::get(
2101 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());
2102 llvm::Value *
V =
Builder.CreateBitCast(RawIntV, PaddedVecTy);
2115 if (VTy != NewVecTy) {
2117 llvm::Value *
V =
Builder.CreateLoad(Cast, Volatile,
"loadVecN");
2118 unsigned OldNumElements = VTy->getNumElements();
2120 std::iota(Mask.begin(), Mask.end(), 0);
2121 V =
Builder.CreateShuffleVector(
V, Mask,
"extractVec");
2136 llvm::LoadInst *Load =
Builder.CreateLoad(
Addr, Volatile);
2137 if (isNontemporal) {
2138 llvm::MDNode *Node = llvm::MDNode::get(
2139 Load->getContext(), llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
2140 Load->setMetadata(llvm::LLVMContext::MD_nontemporal, Node);
2143 CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
2155 Ty = AtomicTy->getValueType();
2159 if (StoreTy->isVectorTy() && StoreTy->getScalarSizeInBits() >
2164 unsigned MemNumElems = StoreTy->getPrimitiveSizeInBits();
2185 Ty = AtomicTy->getValueType();
2191 auto *PaddedVecTy = llvm::FixedVectorType::get(
2192 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());
2212 bool IsVector =
true) {
2213 auto *ArrayTy = dyn_cast<llvm::ArrayType>(
Addr.getElementType());
2214 if (ArrayTy && IsVector) {
2215 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),
2216 ArrayTy->getNumElements());
2218 return Addr.withElementType(VectorTy);
2220 auto *VectorTy = dyn_cast<llvm::VectorType>(
Addr.getElementType());
2221 if (VectorTy && !IsVector) {
2222 auto *ArrayTy = llvm::ArrayType::get(
2223 VectorTy->getElementType(),
2226 return Addr.withElementType(ArrayTy);
2238 value->getType()->isVectorTy());
2240 lvalue.getBaseInfo(), lvalue.getTBAAInfo(), isInit,
2241 lvalue.isNontemporal());
2248 bool isInit,
bool isNontemporal) {
2249 if (
auto *GV = dyn_cast<llvm::GlobalValue>(
Addr.getBasePointer()))
2250 if (GV->isThreadLocal())
2258 if (
auto *VecTy = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
2260 CGM.getABIInfo().getOptimalVectorMemoryType(VecTy,
getLangOpts());
2261 if (!ClangVecTy->isPackedVectorBoolType(
getContext()) &&
2262 VecTy != NewVecTy) {
2264 std::iota(Mask.begin(), Mask.begin() + VecTy->getNumElements(), 0);
2268 if (
Addr.getElementType() != SrcTy)
2269 Addr =
Addr.withElementType(SrcTy);
2286 if (isNontemporal) {
2287 llvm::MDNode *Node =
2288 llvm::MDNode::get(Store->getContext(),
2289 llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
2290 Store->setMetadata(llvm::LLVMContext::MD_nontemporal, Node);
2293 CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
2312 assert(LV.getType()->isConstantMatrixType());
2314 LV.setAddress(
Addr);
2330 llvm_unreachable(
"bad evaluation kind");
2393 if (
CGM.getCodeGenOpts().OptimizationLevel > 0) {
2395 llvm::MatrixBuilder MB(
Builder);
2396 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
2398 llvm::LoadInst *Load =
2403 assert(LV.
isBitField() &&
"Unknown LValue type!");
2421 const unsigned StorageSize =
2424 assert(
static_cast<unsigned>(Offset + Info.
Size) <= StorageSize);
2425 unsigned HighBits = StorageSize - Offset - Info.
Size;
2427 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
2428 if (Offset + HighBits)
2429 Val =
Builder.CreateAShr(Val, Offset + HighBits,
"bf.ashr");
2432 Val =
Builder.CreateLShr(Val, Offset,
"bf.lshr");
2433 if (
static_cast<unsigned>(Offset) + Info.
Size < StorageSize)
2435 Val, llvm::APInt::getLowBitsSet(StorageSize, Info.
Size),
"bf.clear");
2451 llvm::Type *DstTy = llvm::FixedVectorType::get(Vec->getType(), 1);
2452 llvm::Value *
Zero = llvm::Constant::getNullValue(
CGM.Int64Ty);
2453 Vec =
Builder.CreateInsertElement(DstTy, Vec,
Zero,
"cast.splat");
2463 llvm::Value *Elt = llvm::ConstantInt::get(
SizeTy, InIdx);
2465 llvm::Value *Element =
Builder.CreateExtractElement(Vec, Elt);
2468 if (Element->getType()->getPrimitiveSizeInBits() >
2469 LVTy->getPrimitiveSizeInBits())
2470 Element =
Builder.CreateTrunc(Element, LVTy);
2479 for (
unsigned i = 0; i != NumResultElts; ++i)
2482 Vec =
Builder.CreateShuffleVector(Vec, Mask);
2494 llvm::Type *VectorElementTy =
CGM.getTypes().ConvertType(EQT);
2502 Builder.CreateConstInBoundsGEP(CastToPointerElement, ix,
2505 return VectorBasePtrPlusIx;
2511 "Bad type for register variable");
2516 llvm::Type *OrigTy =
CGM.getTypes().ConvertType(LV.
getType());
2517 llvm::Type *Ty = OrigTy;
2518 if (OrigTy->isPointerTy())
2519 Ty =
CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
2520 llvm::Type *Types[] = { Ty };
2522 llvm::Function *F =
CGM.getIntrinsic(llvm::Intrinsic::read_register, Types);
2524 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
2525 if (OrigTy->isPointerTy())
2540 llvm::Type *VecTy = Vec->getType();
2543 if (SrcVal->getType()->getPrimitiveSizeInBits() <
2544 VecTy->getScalarSizeInBits())
2545 SrcVal =
Builder.CreateZExt(SrcVal, VecTy->getScalarType());
2547 auto *IRStoreTy = dyn_cast<llvm::IntegerType>(Vec->getType());
2549 auto *IRVecTy = llvm::FixedVectorType::get(
2550 Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());
2551 Vec =
Builder.CreateBitCast(Vec, IRVecTy);
2558 if (
auto *EltTy = dyn_cast<llvm::FixedVectorType>(SrcVal->getType());
2559 EltTy && EltTy->getNumElements() == 1)
2560 SrcVal =
Builder.CreateBitCast(SrcVal, EltTy->getElementType());
2566 Vec =
Builder.CreateBitCast(Vec, IRStoreTy);
2585 if (
CGM.getCodeGenOpts().OptimizationLevel > 0) {
2587 llvm::MatrixBuilder MB(
Builder);
2588 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
2599 assert(Dst.
isBitField() &&
"Unknown LValue type");
2614 llvm_unreachable(
"present but none");
2649 CGM.getObjCRuntime().EmitObjCWeakAssign(*
this, src, LvalueDst);
2661 llvm::Value *RHS = dst.emitRawPointer(*
this);
2662 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
2664 ResultType,
"sub.ptr.lhs.cast");
2665 llvm::Value *BytesBetween =
Builder.CreateSub(LHS, RHS,
"ivar.offset");
2666 CGM.getObjCRuntime().EmitObjCIvarAssign(*
this, src, dst, BytesBetween);
2668 CGM.getObjCRuntime().EmitObjCGlobalAssign(*
this, src, LvalueDst,
2672 CGM.getObjCRuntime().EmitObjCStrongCastAssign(*
this, src, LvalueDst);
2676 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
2692 llvm::Value *MaskedVal = SrcVal;
2694 const bool UseVolatile =
2697 const unsigned StorageSize =
2702 if (StorageSize != Info.
Size) {
2703 assert(StorageSize > Info.
Size &&
"Invalid bitfield size.");
2710 SrcVal, llvm::APInt::getLowBitsSet(StorageSize, Info.
Size),
2714 SrcVal =
Builder.CreateShl(SrcVal, Offset,
"bf.shl");
2718 Val, ~llvm::APInt::getBitsSet(StorageSize, Offset, Offset + Info.
Size),
2722 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
2724 assert(Offset == 0);
2731 CGM.getCodeGenOpts().ForceAAPCSBitfieldLoad)
2732 Builder.CreateLoad(Ptr,
true,
"bf.load");
2741 llvm::Value *ResultVal = MaskedVal;
2745 assert(Info.
Size <= StorageSize);
2746 unsigned HighBits = StorageSize - Info.
Size;
2748 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
2749 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
2764 SrcVal->getType()->getScalarSizeInBits())
2773 "this should only occur for non-vector l-values");
2781 llvm::Type *VecTy = Vec->getType();
2785 unsigned NumSrcElts = VTy->getNumElements();
2787 if (NumDstElts == NumSrcElts) {
2792 for (
unsigned i = 0; i != NumSrcElts; ++i)
2795 Vec =
Builder.CreateShuffleVector(SrcVal, Mask);
2796 }
else if (NumDstElts > NumSrcElts) {
2802 for (
unsigned i = 0; i != NumSrcElts; ++i)
2803 ExtMask.push_back(i);
2804 ExtMask.resize(NumDstElts, -1);
2805 llvm::Value *ExtSrcVal =
Builder.CreateShuffleVector(SrcVal, ExtMask);
2808 for (
unsigned i = 0; i != NumDstElts; ++i)
2818 for (
unsigned i = 0; i != NumSrcElts; ++i)
2820 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, Mask);
2823 llvm_unreachable(
"unexpected shorten vector length");
2829 llvm::Value *Elt = llvm::ConstantInt::get(
SizeTy, InIdx);
2831 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
2841 "Bad type for register variable");
2844 assert(RegName &&
"Register LValue is not metadata");
2847 llvm::Type *OrigTy =
CGM.getTypes().ConvertType(Dst.
getType());
2848 llvm::Type *Ty = OrigTy;
2849 if (OrigTy->isPointerTy())
2850 Ty =
CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
2851 llvm::Type *Types[] = { Ty };
2853 llvm::Function *F =
CGM.getIntrinsic(llvm::Intrinsic::write_register, Types);
2855 if (OrigTy->isPointerTy())
2858 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName),
Value});
2866 bool IsMemberAccess=
false) {
2878 LV.setObjCIvar(
false);
2882 LV.setObjCIvar(
true);
2884 LV.setBaseIvarExp(Exp->getBase());
2889 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
2890 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
2891 if (VD->hasGlobalStorage()) {
2892 LV.setGlobalObjCRef(
true);
2900 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
2905 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
2907 if (LV.isObjCIvar()) {
2914 LV.setObjCIvar(
false);
2919 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
2924 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
2929 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
2934 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
2939 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
2941 if (LV.isObjCIvar() && !LV.isObjCArray())
2944 LV.setObjCIvar(
false);
2945 else if (LV.isGlobalObjCRef() && !LV.isObjCArray())
2948 LV.setGlobalObjCRef(
false);
2952 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
2966 CGF, VD,
Addr, Loc);
2971 Addr =
Addr.withElementType(RealVarTy);
2977 std::optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res =
2978 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
2982 if (!Res || ((*Res == OMPDeclareTargetDeclAttr::MT_To ||
2983 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&
2986 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||
2987 ((*Res == OMPDeclareTargetDeclAttr::MT_To ||
2988 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&
2990 "Expected link clause OR to clause with unified memory enabled.");
3000 llvm::LoadInst *Load =
3005 PTy, PointeeBaseInfo, PointeeTBAAInfo,
true);
3008 llvm::MDBuilder MDB(Ctx);
3010 if (
CGM.getTypes().getTargetAddressSpace(PTy) == 0 &&
3011 !
CGM.getCodeGenOpts().NullPointerIsValid)
3012 Load->setMetadata(llvm::LLVMContext::MD_nonnull,
3013 llvm::MDNode::get(Ctx, {}));
3019 llvm::LLVMContext::MD_align,
3020 llvm::MDNode::get(Ctx, MDB.createConstant(llvm::ConstantInt::get(
3021 Builder.getInt64Ty(), AlignVal))));
3026 true, PointeeBaseInfo,
3036 PointeeBaseInfo, PointeeTBAAInfo);
3046 BaseInfo, TBAAInfo);
3076 V = CGF.
Builder.CreateThreadLocalAddress(
V);
3084 VD->
hasAttr<OMPThreadPrivateDeclAttr>()) {
3099 if (FD->
hasAttr<WeakRefAttr>()) {
3114 if (
auto *GV = dyn_cast<llvm::GlobalValue>(
V))
3115 V = llvm::NoCFIValue::get(GV);
3122 llvm::Value *ThisValue) {
3135 AsmLabelAttr *
Asm = VD->
getAttr<AsmLabelAttr>();
3136 assert(
Asm->getLabel().size() < 64-Name.size() &&
3137 "Register name too big");
3138 Name.append(
Asm->getLabel());
3139 llvm::NamedMDNode *M =
3140 CGM.
getModule().getOrInsertNamedMetadata(Name);
3141 if (M->getNumOperands() == 0) {
3144 llvm::Metadata *Ops[] = {Str};
3151 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0));
3194 case llvm::GlobalValue::ExternalLinkage:
3195 case llvm::GlobalValue::LinkOnceODRLinkage:
3196 case llvm::GlobalValue::WeakODRLinkage:
3197 case llvm::GlobalValue::InternalLinkage:
3198 case llvm::GlobalValue::PrivateLinkage:
3210 "should not emit an unevaluated operand");
3212 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
3215 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
3223 (VD->getType()->isReferenceType() ||
3225 VD->getAnyInitializer(VD);
3227 E->
getLocation(), *VD->evaluateValue(), VD->getType());
3228 assert(Val &&
"failed to emit constant expression");
3231 if (!VD->getType()->isReferenceType()) {
3233 Addr =
CGM.createUnnamedGlobalFrom(*VD, Val,
3236 auto *PTy = llvm::PointerType::get(
3255 VD = VD->getCanonicalDecl();
3259 auto I = LocalDeclMap.find(VD);
3260 if (I != LocalDeclMap.end()) {
3262 if (VD->getType()->isReferenceType())
3270 CGM.getOpenMPRuntime().isNontemporalDecl(VD))
3287 CGM.getOpenMPRuntime().isNontemporalDecl(VD))
3303 "Should not use decl without marking it used!");
3305 if (ND->
hasAttr<WeakRefAttr>()) {
3311 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
3313 if (VD->hasLinkage() || VD->isStaticDataMember())
3319 auto iter = LocalDeclMap.find(VD);
3320 if (iter != LocalDeclMap.end()) {
3321 addr = iter->second;
3325 }
else if (VD->isStaticLocal()) {
3326 llvm::Constant *var =
CGM.getOrCreateStaticVarDecl(
3327 *VD,
CGM.getLLVMLinkageVarDefinition(VD));
3333 llvm_unreachable(
"DeclRefExpr for Decl not entered in LocalDeclMap?");
3344 VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
3351 bool isBlockByref = VD->isEscapingByref();
3357 LValue LV = VD->getType()->isReferenceType() ?
3361 bool isLocalStorage = VD->hasLocalStorage();
3363 bool NonGCable = isLocalStorage &&
3364 !VD->getType()->isReferenceType() &&
3371 bool isImpreciseLifetime =
3372 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
3373 if (isImpreciseLifetime)
3379 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
3385 if (
const auto *BD = dyn_cast<BindingDecl>(ND)) {
3402 if (
const auto *GD = dyn_cast<MSGuidDecl>(ND))
3406 if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
3407 auto ATPO =
CGM.GetAddrOfTemplateParamObject(TPO);
3410 if (AS !=
T.getAddressSpace()) {
3412 auto PtrTy = llvm::PointerType::get(
CGM.getLLVMContext(), TargetAS);
3415 ATPO =
ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
3421 llvm_unreachable(
"Unhandled DeclRefExpr");
3431 default: llvm_unreachable(
"Unknown unary operator lvalue!");
3434 assert(!
T.isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
3456 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
3473 CGM.getTBAAInfoForSubobject(LV,
T));
3480 bool isInc = E->
getOpcode() == UO_PreInc;
3503 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
3504 StringRef FnName =
CurFn->getName();
3505 FnName.consume_front(
"\01");
3506 StringRef NameItems[] = {
3508 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
3509 if (
auto *BD = dyn_cast_or_null<BlockDecl>(
CurCodeDecl)) {
3510 std::string Name = std::string(SL->getString());
3511 if (!Name.empty()) {
3512 unsigned Discriminator =
3513 CGM.getCXXABI().getMangleContext().getBlockId(BD,
true);
3515 Name +=
"_" + Twine(Discriminator + 1).str();
3516 auto C =
CGM.GetAddrOfConstantCString(Name, GVName);
3519 auto C =
CGM.GetAddrOfConstantCString(std::string(FnName), GVName);
3523 auto C =
CGM.GetAddrOfConstantStringFromLiteral(SL, GVName);
3540 if (llvm::Constant *
C =
CGM.getTypeDescriptorFromMap(
T))
3545 bool IsBitInt =
false;
3547 if (
T->isIntegerType()) {
3550 (
T->isSignedIntegerType() ? 1 : 0);
3554 if (
T->isSignedIntegerType() &&
T->getAs<
BitIntType>()) {
3557 " non positive amount of bits in __BitInt type");
3559 " too many bits in __BitInt type");
3566 }
else if (
T->isFloatingType()) {
3575 (
intptr_t)
T.getAsOpaquePtr(), StringRef(),
3576 StringRef(), {}, Buffer, {});
3581 char S[6] = {
'\0',
'\0',
'\0',
'\0',
'\0',
'\0'};
3584 llvm::support::endian::write32(S + 1, Bits,
3586 ? llvm::endianness::big
3587 : llvm::endianness::little);
3588 StringRef Str = StringRef(S,
sizeof(S) /
sizeof(
decltype(S[0])));
3592 llvm::Constant *Components[] = {
3596 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
3598 auto *GV =
new llvm::GlobalVariable(
3599 CGM.getModule(), Descriptor->getType(),
3600 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
3601 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3602 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(GV);
3605 CGM.setTypeDescriptorInMap(
T, GV);
3613 if (
V->getType() == TargetTy)
3618 if (
V->getType()->isFloatingPointTy()) {
3619 unsigned Bits =
V->getType()->getPrimitiveSizeInBits().getFixedValue();
3620 if (Bits <= TargetTy->getIntegerBitWidth())
3626 if (
V->getType()->isIntegerTy() &&
3627 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
3628 return Builder.CreateZExt(
V, TargetTy);
3631 if (!
V->getType()->isPointerTy()) {
3636 return Builder.CreatePtrToInt(
V, TargetTy);
3649 llvm::Constant *Filename;
3656 int PathComponentsToStrip =
3657 CGM.getCodeGenOpts().EmitCheckPathComponentsToStrip;
3658 if (PathComponentsToStrip < 0) {
3659 assert(PathComponentsToStrip !=
INT_MIN);
3660 int PathComponentsToKeep = -PathComponentsToStrip;
3661 auto I = llvm::sys::path::rbegin(FilenameString);
3662 auto E = llvm::sys::path::rend(FilenameString);
3663 while (I != E && --PathComponentsToKeep)
3666 FilenameString = FilenameString.substr(I - E);
3667 }
else if (PathComponentsToStrip > 0) {
3668 auto I = llvm::sys::path::begin(FilenameString);
3669 auto E = llvm::sys::path::end(FilenameString);
3670 while (I != E && PathComponentsToStrip--)
3675 FilenameString.substr(I - llvm::sys::path::begin(FilenameString));
3677 FilenameString = llvm::sys::path::filename(FilenameString);
3681 CGM.GetAddrOfConstantCString(std::string(FilenameString),
".src");
3682 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(
3684 FilenameGV.getPointer()->stripPointerCasts()));
3685 Filename = FilenameGV.getPointer();
3689 Filename = llvm::Constant::getNullValue(
Int8PtrTy);
3696 return llvm::ConstantStruct::getAnon(
Data);
3701enum class CheckRecoverableKind {
3712static CheckRecoverableKind
3714 if (Ordinal == SanitizerKind::SO_Vptr)
3715 return CheckRecoverableKind::AlwaysRecoverable;
3716 else if (Ordinal == SanitizerKind::SO_Return ||
3717 Ordinal == SanitizerKind::SO_Unreachable)
3718 return CheckRecoverableKind::Unrecoverable;
3720 return CheckRecoverableKind::Recoverable;
3724struct SanitizerHandlerInfo {
3725 char const *
const Name;
3731#define SANITIZER_CHECK(Enum, Name, Version, Msg) {#Name, Version},
3733#undef SANITIZER_CHECK
3737 llvm::FunctionType *FnType,
3740 CheckRecoverableKind RecoverKind,
bool IsFatal,
3741 llvm::BasicBlock *ContBB,
bool NoMerge) {
3742 assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
3743 std::optional<ApplyDebugLocation> DL;
3744 if (!CGF.
Builder.getCurrentDebugLocation()) {
3748 bool NeedsAbortSuffix =
3749 IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable;
3752 const StringRef CheckName = CheckInfo.Name;
3753 std::string FnName =
"__ubsan_handle_" + CheckName.str();
3754 if (CheckInfo.Version && !MinimalRuntime)
3755 FnName +=
"_v" + llvm::utostr(CheckInfo.Version);
3757 FnName +=
"_minimal";
3758 if (NeedsAbortSuffix)
3761 !IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;
3765 B.addAttribute(llvm::Attribute::NoReturn)
3766 .addAttribute(llvm::Attribute::NoUnwind);
3768 B.addUWTableAttr(llvm::UWTableKind::Default);
3773 llvm::AttributeList::FunctionIndex, B),
3779 HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
3781 HandlerCall->setDoesNotReturn();
3782 CGF.
Builder.CreateUnreachable();
3789 ArrayRef<std::pair<llvm::Value *, SanitizerKind::SanitizerOrdinal>> Checked,
3793 assert(Checked.size() > 0);
3794 assert(CheckHandler >= 0 &&
3798 llvm::Value *FatalCond =
nullptr;
3799 llvm::Value *RecoverableCond =
nullptr;
3800 llvm::Value *TrapCond =
nullptr;
3801 bool NoMerge =
false;
3808 for (
auto &[Check, Ord] : Checked) {
3809 llvm::Value *GuardedCheck = Check;
3811 (
CGM.getCodeGenOpts().SanitizeSkipHotCutoffs[Ord] > 0)) {
3813 CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
3814 llvm::ConstantInt::get(
CGM.Int8Ty, Ord));
3819 llvm::Value *&
Cond =
CGM.getCodeGenOpts().SanitizeTrap.has(Ord) ? TrapCond
3820 :
CGM.getCodeGenOpts().SanitizeRecover.has(Ord)
3825 if (!
CGM.getCodeGenOpts().SanitizeMergeHandlers.has(Ord))
3831 if (!FatalCond && !RecoverableCond)
3834 llvm::Value *JointCond;
3835 if (FatalCond && RecoverableCond)
3836 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
3838 JointCond = FatalCond ? FatalCond : RecoverableCond;
3842 assert(
SanOpts.has(Checked[0].second));
3844 for (
int i = 1, n = Checked.size(); i < n; ++i) {
3846 "All recoverable kinds in a single check must be same!");
3847 assert(
SanOpts.has(Checked[i].second));
3853 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
3856 llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();
3857 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
3861 if (
CGM.getCodeGenOpts().SanitizeMinimalRuntime) {
3862 switch (CheckHandler) {
3863 case SanitizerHandler::TypeMismatch:
3866 assert(DynamicArgs.size() == 1);
3882 Args.reserve(DynamicArgs.size() + 1);
3883 ArgTypes.reserve(DynamicArgs.size() + 1);
3886 if (!StaticArgs.empty()) {
3887 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3888 auto *InfoPtr =
new llvm::GlobalVariable(
3889 CGM.getModule(), Info->getType(),
3892 false, llvm::GlobalVariable::PrivateLinkage, Info,
"",
3893 nullptr, llvm::GlobalVariable::NotThreadLocal,
3894 CGM.getDataLayout().getDefaultGlobalsAddressSpace());
3895 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3896 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr);
3897 Args.push_back(InfoPtr);
3898 ArgTypes.push_back(Args.back()->getType());
3901 for (llvm::Value *DynamicArg : DynamicArgs) {
3906 llvm::FunctionType *FnType =
3907 llvm::FunctionType::get(
CGM.VoidTy, ArgTypes,
false);
3909 if (!FatalCond || !RecoverableCond) {
3913 (FatalCond !=
nullptr), Cont, NoMerge);
3917 llvm::BasicBlock *NonFatalHandlerBB =
3920 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
3923 NonFatalHandlerBB, NoMerge);
3934 llvm::ConstantInt *TypeId, llvm::Value *Ptr,
3939 llvm::BranchInst *BI =
Builder.CreateCondBr(
Cond, Cont, CheckBB);
3942 llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();
3943 BI->setMetadata(llvm::LLVMContext::MD_prof, Node);
3947 bool WithDiag = !
CGM.getCodeGenOpts().SanitizeTrap.has(Ordinal);
3949 llvm::CallInst *CheckCall;
3950 llvm::FunctionCallee SlowPathFn;
3952 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3954 new llvm::GlobalVariable(
CGM.getModule(), Info->getType(),
false,
3955 llvm::GlobalVariable::PrivateLinkage, Info);
3956 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3957 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr);
3959 SlowPathFn =
CGM.getModule().getOrInsertFunction(
3960 "__cfi_slowpath_diag",
3963 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr, InfoPtr});
3965 SlowPathFn =
CGM.getModule().getOrInsertFunction(
3968 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
3973 CheckCall->setDoesNotThrow();
3981 llvm::Module *M = &
CGM.getModule();
3983 QualType QInt64Ty =
C.getIntTypeForBitwidth(64,
false);
3990 FnArgs.push_back(&ArgCallsiteTypeId);
3991 FnArgs.push_back(&ArgAddr);
3992 FnArgs.push_back(&ArgCFICheckFailData);
3994 CGM.getTypes().arrangeBuiltinFunctionDeclaration(
C.VoidTy,
FnArgs);
3996 llvm::Function *F = llvm::Function::Create(
3998 llvm::GlobalValue::WeakAnyLinkage,
"__cfi_check", M);
4000 CGM.SetLLVMFunctionAttributesForDefinition(
nullptr, F);
4001 F->setAlignment(llvm::Align(4096));
4004 llvm::LLVMContext &Ctx = M->getContext();
4005 llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx,
"entry", F);
4008 llvm::CallInst::Create(M->getFunction(
"__cfi_check_fail"), Args,
"", BB);
4009 llvm::ReturnInst::Create(Ctx,
nullptr, BB);
4020 auto CheckHandler = SanitizerHandler::CFICheckFail;
4027 {SanitizerKind::SO_CFIVCall, SanitizerKind::SO_CFINVCall,
4028 SanitizerKind::SO_CFIDerivedCast, SanitizerKind::SO_CFIUnrelatedCast,
4029 SanitizerKind::SO_CFIICall},
4036 Args.push_back(&ArgData);
4037 Args.push_back(&ArgAddr);
4042 llvm::Function *F = llvm::Function::Create(
4044 llvm::GlobalValue::WeakODRLinkage,
"__cfi_check_fail", &
CGM.getModule());
4047 CGM.SetLLVMFunctionAttributesForDefinition(
nullptr, F);
4048 F->setVisibility(llvm::GlobalValue::HiddenVisibility);
4068 llvm::Value *DataIsNotNullPtr =
4073 EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail,
4076 llvm::StructType *SourceLocationTy =
4078 llvm::StructType *CfiCheckFailDataTy =
4081 llvm::Value *
V =
Builder.CreateConstGEP2_32(
4085 llvm::Value *CheckKind =
Builder.CreateLoad(CheckKindAddr);
4087 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
4088 CGM.getLLVMContext(),
4089 llvm::MDString::get(
CGM.getLLVMContext(),
"all-vtables"));
4090 llvm::Value *ValidVtable =
Builder.CreateZExt(
4091 Builder.CreateCall(
CGM.getIntrinsic(llvm::Intrinsic::type_test),
4092 {Addr, AllVtables}),
4095 const std::pair<int, SanitizerKind::SanitizerOrdinal> CheckKinds[] = {
4102 for (
auto CheckKindOrdinalPair : CheckKinds) {
4103 int Kind = CheckKindOrdinalPair.first;
4110 Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(
Int8Ty, Kind));
4111 if (
CGM.getLangOpts().Sanitize.has(Ordinal))
4112 EmitCheck(std::make_pair(
Cond, Ordinal), SanitizerHandler::CFICheckFail,
4125 CGM.addUsedGlobal(F);
4129 if (
SanOpts.has(SanitizerKind::Unreachable)) {
4130 auto CheckOrdinal = SanitizerKind::SO_Unreachable;
4131 auto CheckHandler = SanitizerHandler::BuiltinUnreachable;
4147 if ((
int)TrapBBs.size() <= CheckHandlerID)
4148 TrapBBs.resize(CheckHandlerID + 1);
4150 llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];
4152 llvm::DILocation *TrapLocation =
Builder.getCurrentDebugLocation();
4153 llvm::StringRef TrapMessage;
4154 llvm::StringRef TrapCategory;
4155 auto DebugTrapReasonKind =
CGM.getCodeGenOpts().getSanitizeDebugTrapReasons();
4157 DebugTrapReasonKind ==
4163 TrapCategory =
"Undefined Behavior Sanitizer";
4167 DebugTrapReasonKind !=
4171 TrapLocation, TrapCategory, TrapMessage);
4174 NoMerge = NoMerge || !
CGM.getCodeGenOpts().OptimizationLevel ||
4178 if (TrapBB && !NoMerge) {
4179 auto Call = TrapBB->begin();
4182 Call->applyMergedLocation(
Call->getDebugLoc(), TrapLocation);
4184 Builder.CreateCondBr(Checked, Cont, TrapBB,
4185 MDHelper.createLikelyBranchWeights());
4188 Builder.CreateCondBr(Checked, Cont, TrapBB,
4189 MDHelper.createLikelyBranchWeights());
4194 llvm::CallInst *TrapCall =
4195 Builder.CreateCall(
CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
4196 llvm::ConstantInt::get(
CGM.Int8Ty, CheckHandlerID));
4198 if (!
CGM.getCodeGenOpts().TrapFuncName.empty()) {
4199 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
4200 CGM.getCodeGenOpts().TrapFuncName);
4201 TrapCall->addFnAttr(A);
4204 TrapCall->addFnAttr(llvm::Attribute::NoMerge);
4205 TrapCall->setDoesNotReturn();
4206 TrapCall->setDoesNotThrow();
4214 llvm::CallInst *TrapCall =
4215 Builder.CreateCall(
CGM.getIntrinsic(IntrID));
4217 if (!
CGM.getCodeGenOpts().TrapFuncName.empty()) {
4218 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
4219 CGM.getCodeGenOpts().TrapFuncName);
4220 TrapCall->addFnAttr(A);
4224 TrapCall->addFnAttr(llvm::Attribute::NoMerge);
4232 "Array to pointer decay must have array source type!");
4241 Addr =
Addr.withElementType(NewTy);
4247 "Expected pointer to array");
4258 if (TBAAInfo) *TBAAInfo =
CGM.getTBAAAccessInfo(EltType);
4267 const auto *CE = dyn_cast<CastExpr>(E);
4268 if (!CE || CE->getCastKind() != CK_ArrayToPointerDecay)
4280 llvm::Type *elemType,
4286 const llvm::Twine &name =
"arrayidx") {
4298 llvm::Type *elementType,
bool inbounds,
4301 const llvm::Twine &name =
"arrayidx") {
4321 return D && D->
hasAttr<BPFPreserveStaticOffsetAttr>();
4328 if (PointeeType.
isNull())
4341 llvm::Function *Fn =
4343 llvm::CallInst *
Call = CGF.
Builder.CreateCall(Fn, {
Addr.emitRawPointer(CGF)});
4361 if (
const auto *ME = dyn_cast<MemberExpr>(E))
4362 return ME->getMemberDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
4364 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
4365 const auto *VarDef = dyn_cast<VarDecl>(DRE->getDecl());
4369 const auto *PtrT = VarDef->getType()->getAs<
PointerType>();
4375 if (
const auto *RecT = dyn_cast<RecordType>(PointeeT))
4376 return RecT->getOriginalDecl()
4377 ->getMostRecentDecl()
4378 ->
hasAttr<BPFPreserveAccessIndexAttr>();
4391 const llvm::Twine &name =
"arrayidx") {
4394 for (
auto *idx : indices.drop_back())
4413 llvm::Value *eltPtr;
4414 auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
4419 signedIndices, loc, eltAlign, name);
4423 unsigned idx = LastIndex->getZExtValue();
4424 llvm::DIType *DbgInfo =
nullptr;
4427 eltPtr = CGF.
Builder.CreatePreserveArrayAccessIndex(
4439struct StructFieldAccess
4440 :
public ConstStmtVisitor<StructFieldAccess, const Expr *> {
4441 const Expr *VisitCastExpr(
const CastExpr *E) {
4446 const Expr *VisitParenExpr(
const ParenExpr *E) {
4455 const FieldDecl *Field, int64_t &Offset) {
4458 unsigned FieldNo = 0;
4493 if (FD1OuterRec != FD2OuterRec)
4495 return std::optional<int64_t>();
4497 int64_t FD1Offset = 0;
4499 return std::optional<int64_t>();
4501 int64_t FD2Offset = 0;
4503 return std::optional<int64_t>();
4505 return std::make_optional<int64_t>(FD1Offset - FD2Offset);
4517 QualType ArrayTy,
bool Accessed,
bool FlexibleArray) {
4519 if (!ME || !ME->getMemberDecl()->getType()->isCountAttributedType())
4524 if (FlexibleArray &&
4525 !ME->isFlexibleArrayMemberLike(
getContext(), StrictFlexArraysLevel))
4533 if (std::optional<int64_t> Diff =
4535 if (!
Addr.isValid()) {
4553 Builder.getInt32(*Diff),
".counted_by.gep");
4555 ".counted_by.load");
4566 llvm::Value *IdxPre =
4568 bool SignedIndices =
false;
4569 auto EmitIdxAfterBase = [&, IdxPre](
bool Promote) -> llvm::Value * {
4572 assert(E->
getRHS() == E->
getIdx() &&
"index was neither LHS nor RHS");
4578 SignedIndices |= IdxSigned;
4580 if (
SanOpts.has(SanitizerKind::ArrayBounds))
4584 if (Promote && Idx->getType() !=
IntPtrTy)
4597 auto *Idx = EmitIdxAfterBase(
false);
4598 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
4606 std::optional<LValue> LV =
4607 CGM.getHLSLRuntime().emitResourceArraySubscriptExpr(E, *
this);
4617 auto *Idx = EmitIdxAfterBase(
true);
4624 CGM.getTBAAInfoForSubobject(LV, EltType));
4636 auto *Idx = EmitIdxAfterBase(
true);
4646 Idx =
Builder.CreateMul(Idx, numElements);
4648 Idx =
Builder.CreateNSWMul(Idx, numElements);
4660 auto *Idx = EmitIdxAfterBase(
true);
4663 llvm::Value *InterfaceSizeVal =
4664 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.
getQuantity());
4666 llvm::Value *ScaledIdx =
Builder.CreateMul(Idx, InterfaceSizeVal);
4672 llvm::Type *OrigBaseElemTy =
Addr.getElementType();
4677 llvm::Value *EltPtr =
4679 ScaledIdx,
false, SignedIndices, E->
getExprLoc());
4686 assert(Array->getType()->isArrayType() &&
4687 "Array to pointer decay must have array source type!");
4691 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
4695 auto *Idx = EmitIdxAfterBase(
true);
4697 if (
SanOpts.has(SanitizerKind::ArrayBounds))
4705 *
this, ArrayLV.
getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},
4709 if (!
CGM.getCodeGenOpts().NewStructPathTBAA) {
4712 EltTBAAInfo =
CGM.getTBAAInfoForSubobject(ArrayLV, E->
getType());
4717 EltTBAAInfo =
CGM.getTBAAAccessInfo(E->
getType());
4739 auto *Idx = EmitIdxAfterBase(
true);
4746 if (
SanOpts.has(SanitizerKind::ArrayBounds)) {
4747 StructFieldAccess Visitor;
4750 if (
const auto *CE = dyn_cast_if_present<CastExpr>(
Base);
4751 CE && CE->getCastKind() == CK_LValueToRValue)
4779 "incomplete matrix subscript expressions should be rejected during Sema");
4786 llvm::Value *NumRows =
Builder.getIntN(
4787 RowIdx->getType()->getScalarSizeInBits(),
4789 llvm::Value *FinalIdx =
4800 bool IsLowerBound) {
4802 if (
auto *ASE = dyn_cast<ArraySectionExpr>(
Base->IgnoreParenImpCasts())) {
4806 BaseInfo = BaseLVal.getBaseInfo();
4811 Addr =
Addr.withElementType(NewTy);
4817 "Expected pointer to array");
4827 BaseInfo.mergeForCast(TypeBaseInfo);
4836 bool IsLowerBound) {
4839 "OpenACC Array section codegen not implemented");
4843 if (
auto *AT =
getContext().getAsArrayType(BaseTy))
4844 ResultExprTy = AT->getElementType();
4847 llvm::Value *Idx =
nullptr;
4855 LowerBound->getType()->hasSignedIntegerRepresentation());
4857 Idx = llvm::ConstantInt::getNullValue(
IntPtrTy);
4862 auto &
C =
CGM.getContext();
4864 llvm::APSInt ConstLength;
4867 if (std::optional<llvm::APSInt>
CL = Length->getIntegerConstantExpr(
C)) {
4874 if (std::optional<llvm::APSInt> LB =
4875 LowerBound->getIntegerConstantExpr(
C)) {
4877 LowerBound =
nullptr;
4882 else if (!LowerBound)
4885 if (Length || LowerBound) {
4886 auto *LowerBoundVal =
4890 LowerBound->getType()->hasSignedIntegerRepresentation())
4891 : llvm::ConstantInt::get(
IntPtrTy, ConstLowerBound);
4896 Length->getType()->hasSignedIntegerRepresentation())
4897 : llvm::ConstantInt::get(
IntPtrTy, ConstLength);
4898 Idx =
Builder.CreateAdd(LowerBoundVal, LengthVal,
"lb_add_len",
4901 if (Length && LowerBound) {
4903 Idx, llvm::ConstantInt::get(
IntPtrTy, 1),
"idx_sub_1",
4907 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength + ConstLowerBound);
4913 if (
auto *VAT =
C.getAsVariableArrayType(ArrayTy)) {
4914 Length = VAT->getSizeExpr();
4915 if (std::optional<llvm::APSInt> L = Length->getIntegerConstantExpr(
C)) {
4920 auto *CAT =
C.getAsConstantArrayType(ArrayTy);
4921 assert(CAT &&
"unexpected type for array initializer");
4922 ConstLength = CAT->getSize();
4925 auto *LengthVal =
Builder.CreateIntCast(
4927 Length->getType()->hasSignedIntegerRepresentation());
4929 LengthVal, llvm::ConstantInt::get(
IntPtrTy, 1),
"len_sub_1",
4934 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength);
4943 if (
auto *VLA =
getContext().getAsVariableArrayType(ResultExprTy)) {
4949 BaseTy, VLA->getElementType(), IsLowerBound);
4958 Idx =
Builder.CreateMul(Idx, NumElements);
4960 Idx =
Builder.CreateNSWMul(Idx, NumElements);
4969 assert(Array->getType()->isArrayType() &&
4970 "Array to pointer decay must have array source type!");
4974 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
4981 *
this, ArrayLV.
getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},
4982 ResultExprTy, !
getLangOpts().PointerOverflowDefined,
4985 TBAAInfo =
CGM.getTBAAInfoForSubobject(ArrayLV, ResultExprTy);
4989 ResultExprTy, IsLowerBound);
5012 Base.getQuals().removeObjCGCAttr();
5021 "Result must be a vector");
5029 if (LTy->getScalarSizeInBits() > Vec->getType()->getScalarSizeInBits())
5030 Vec =
Builder.CreateZExt(Vec, LTy);
5031 Builder.CreateStore(Vec, VecMem);
5042 if (
Base.isSimple()) {
5043 llvm::Constant *CV =
5048 assert(
Base.isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
5050 llvm::Constant *BaseElts =
Base.getExtVectorElts();
5053 for (
unsigned Index : Indices)
5054 CElts.push_back(BaseElts->getAggregateElement(Index));
5055 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
5062 while (
auto *BaseMemberExpr = dyn_cast<MemberExpr>(UnderlyingBaseExpr))
5063 UnderlyingBaseExpr = BaseMemberExpr->getBase()->
IgnoreParens();
5077 bool IsInBounds = !
getLangOpts().PointerOverflowDefined &&
5089 SkippedChecks.
set(SanitizerKind::Alignment,
true);
5091 SkippedChecks.
set(SanitizerKind::Null,
true);
5099 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
5107 CGM.getOpenMPRuntime().isNontemporalDecl(Field)) ||
5114 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
5117 llvm_unreachable(
"Unhandled member declaration!");
5124 llvm::Value *ThisValue) {
5125 bool HasExplicitObjectParameter =
false;
5126 const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
CurCodeDecl);
5128 HasExplicitObjectParameter = MD->isExplicitObjectMemberFunction();
5129 assert(MD->getParent()->isLambda());
5130 assert(MD->getParent() == Field->getParent());
5133 if (HasExplicitObjectParameter) {
5135 auto It = LocalDeclMap.find(D);
5136 assert(It != LocalDeclMap.end() &&
"explicit parameter not loaded?");
5137 Address AddrOfExplicitObject = It->getSecond();
5148 if (ThisTy != LambdaTy) {
5151 LambdaLV.
getAddress(), ThisTy, BasePathArray.begin(),
5171 unsigned FieldIndex) {
5172 unsigned I = 0, Skipped = 0;
5175 if (I == FieldIndex)
5177 if (F->isUnnamedBitField())
5182 return FieldIndex - Skipped;
5192 if (Offset.isZero())
5205 const FieldDecl *field,
bool IsInBounds) {
5238 if (RD->isDynamicClass())
5241 for (
const auto &
Base : RD->bases())
5245 for (
const FieldDecl *Field : RD->fields())
5260 const bool UseVolatile =
isAAPCS(
CGM.getTarget()) &&
5261 CGM.getCodeGenOpts().AAPCSBitfieldWidth &&
5292 llvm::Type *FieldIntTy = llvm::Type::getIntNTy(
getLLVMContext(), SS);
5293 Addr =
Addr.withElementType(FieldIntTy);
5328 assert(!FieldTBAAInfo.
Offset &&
5329 "Nonzero offset for an access with no base type!");
5342 FieldTBAAInfo.
Size =
5349 if (
auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) {
5350 if (
CGM.getCodeGenOpts().StrictVTablePointers &&
5351 ClassDef->isDynamicClass()) {
5365 if (
CGM.getCodeGenOpts().StrictVTablePointers &&
5369 addr =
Builder.CreateLaunderInvariantGroup(addr);
5412 if (field->
hasAttr<AnnotateAttr>())
5428 QualType FieldType = Field->getType();
5434 *
this,
Base.getAddress(), Field,
5439 V =
V.withElementType(llvmType);
5448 CGM.getTBAAInfoForSubobject(
Base, FieldType));
5484 assert(E->
isTransparent() &&
"non-transparent glvalue init list");
5492 const Expr *Operand) {
5493 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->IgnoreParens())) {
5495 return std::nullopt;
5504std::optional<LValue> HandleConditionalOperatorLValueSimpleCase(
5506 const Expr *condExpr = E->
getCond();
5511 std::swap(Live, Dead);
5520 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Live->
IgnoreParens())) {
5522 llvm::Type *ElemTy = CGF.
ConvertType(Dead->getType());
5531 return std::nullopt;
5533struct ConditionalInfo {
5534 llvm::BasicBlock *lhsBlock, *rhsBlock;
5535 std::optional<LValue> LHS, RHS;
5540template<
typename FuncTy>
5542 const AbstractConditionalOperator *E,
5543 const FuncTy &BranchGenFunc) {
5559 Info.lhsBlock = CGF.
Builder.GetInsertBlock();
5562 CGF.
Builder.CreateBr(endBlock);
5569 Info.rhsBlock = CGF.
Builder.GetInsertBlock();
5581 "Unexpected conditional operator!");
5586 if (HandleConditionalOperatorLValueSimpleCase(*
this, E))
5589 EmitConditionalBlocks(*
this, E, [](CodeGenFunction &CGF,
const Expr *E) {
5596 if (!
expr->isGLValue()) {
5599 "Unexpected conditional operator!");
5604 if (std::optional<LValue> Res =
5605 HandleConditionalOperatorLValueSimpleCase(*
this,
expr))
5608 ConditionalInfo Info = EmitConditionalBlocks(
5609 *
this,
expr, [](CodeGenFunction &CGF,
const Expr *E) {
5613 if ((Info.LHS && !Info.LHS->isSimple()) ||
5614 (Info.RHS && !Info.RHS->isSimple()))
5617 if (Info.LHS && Info.RHS) {
5618 Address lhsAddr = Info.LHS->getAddress();
5619 Address rhsAddr = Info.RHS->getAddress();
5621 lhsAddr, rhsAddr, Info.lhsBlock, Info.rhsBlock,
5624 std::max(Info.LHS->getBaseInfo().getAlignmentSource(),
5625 Info.RHS->getBaseInfo().getAlignmentSource());
5627 Info.LHS->getTBAAInfo(), Info.RHS->getTBAAInfo());
5631 assert((Info.LHS || Info.RHS) &&
5632 "both operands of glvalue conditional are throw-expressions?");
5633 return Info.LHS ? *Info.LHS : *Info.RHS;
5648 case CK_LValueToRValueBitCast:
5649 case CK_ArrayToPointerDecay:
5650 case CK_FunctionToPointerDecay:
5651 case CK_NullToMemberPointer:
5652 case CK_NullToPointer:
5653 case CK_IntegralToPointer:
5654 case CK_PointerToIntegral:
5655 case CK_PointerToBoolean:
5656 case CK_IntegralCast:
5657 case CK_BooleanToSignedIntegral:
5658 case CK_IntegralToBoolean:
5659 case CK_IntegralToFloating:
5660 case CK_FloatingToIntegral:
5661 case CK_FloatingToBoolean:
5662 case CK_FloatingCast:
5663 case CK_FloatingRealToComplex:
5664 case CK_FloatingComplexToReal:
5665 case CK_FloatingComplexToBoolean:
5666 case CK_FloatingComplexCast:
5667 case CK_FloatingComplexToIntegralComplex:
5668 case CK_IntegralRealToComplex:
5669 case CK_IntegralComplexToReal:
5670 case CK_IntegralComplexToBoolean:
5671 case CK_IntegralComplexCast:
5672 case CK_IntegralComplexToFloatingComplex:
5673 case CK_DerivedToBaseMemberPointer:
5674 case CK_BaseToDerivedMemberPointer:
5675 case CK_MemberPointerToBoolean:
5676 case CK_ReinterpretMemberPointer:
5677 case CK_AnyPointerToBlockPointerCast:
5678 case CK_ARCProduceObject:
5679 case CK_ARCConsumeObject:
5680 case CK_ARCReclaimReturnedObject:
5681 case CK_ARCExtendBlockObject:
5682 case CK_CopyAndAutoreleaseBlockObject:
5683 case CK_IntToOCLSampler:
5684 case CK_FloatingToFixedPoint:
5685 case CK_FixedPointToFloating:
5686 case CK_FixedPointCast:
5687 case CK_FixedPointToBoolean:
5688 case CK_FixedPointToIntegral:
5689 case CK_IntegralToFixedPoint:
5691 case CK_HLSLVectorTruncation:
5692 case CK_HLSLArrayRValue:
5693 case CK_HLSLElementwiseCast:
5694 case CK_HLSLAggregateSplatCast:
5698 llvm_unreachable(
"dependent cast kind in IR gen!");
5700 case CK_BuiltinFnToFnPtr:
5701 llvm_unreachable(
"builtin functions are handled elsewhere");
5704 case CK_NonAtomicToAtomic:
5705 case CK_AtomicToNonAtomic:
5715 case CK_ConstructorConversion:
5716 case CK_UserDefinedConversion:
5717 case CK_CPointerToObjCPointerCast:
5718 case CK_BlockPointerToObjCPointerCast:
5719 case CK_LValueToRValue:
5734 if (
V.getElementType() !=
T)
5741 case CK_UncheckedDerivedToBase:
5742 case CK_DerivedToBase: {
5756 CGM.getTBAAInfoForSubobject(LV, E->
getType()));
5760 case CK_BaseToDerived: {
5775 if (
SanOpts.has(SanitizerKind::CFIDerivedCast))
5781 CGM.getTBAAInfoForSubobject(LV, E->
getType()));
5783 case CK_LValueBitCast: {
5787 CGM.EmitExplicitCastExprType(CE,
this);
5792 if (
SanOpts.has(SanitizerKind::CFIUnrelatedCast))
5798 CGM.getTBAAInfoForSubobject(LV, E->
getType()));
5800 case CK_AddressSpaceConversion: {
5810 case CK_ObjCObjectLValueCast: {
5814 CGM.getTBAAInfoForSubobject(LV, E->
getType()));
5816 case CK_ZeroToOCLOpaqueType:
5817 llvm_unreachable(
"NULL to OpenCL opaque type lvalue cast is not valid");
5819 case CK_VectorSplat: {
5827 llvm_unreachable(
"Unhandled lvalue cast kind?");
5835std::pair<LValue, LValue>
5850 return std::make_pair(BaseLV, TempLV);
5858 llvm::Value *
Addr = TempLV.getAddress().getBasePointer();
5863 Address TmpAddr(
Addr, ElTy, TempLV.getAlignment());
5873 llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
5874 it = OpaqueLValues.find(e);
5876 if (it != OpaqueLValues.end())
5879 assert(e->
isUnique() &&
"LValue for a nonunique OVE hasn't been emitted");
5887 llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
5888 it = OpaqueRValues.find(e);
5890 if (it != OpaqueRValues.end())
5893 assert(e->
isUnique() &&
"RValue for a nonunique OVE hasn't been emitted");
5899 return OpaqueLValues.contains(E);
5900 return OpaqueRValues.contains(E);
5924 llvm_unreachable(
"bad evaluation kind");
5933 llvm::CallBase **CallOrInvoke) {
5934 llvm::CallBase *CallOrInvokeStorage;
5935 if (!CallOrInvoke) {
5936 CallOrInvoke = &CallOrInvokeStorage;
5939 auto AddCoroElideSafeOnExit = llvm::make_scope_exit([&] {
5941 auto *I = *CallOrInvoke;
5943 I->addFnAttr(llvm::Attribute::CoroElideSafe);
5951 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
5954 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
5959 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
5960 if (
const auto *MD =
5961 dyn_cast_if_present<CXXMethodDecl>(CE->getCalleeDecl());
5962 MD && MD->isImplicitObjectMemberFunction())
5977 nullptr, CallOrInvoke);
5983 llvm::CallBase **CallOrInvoke) {
5986 nullptr, CallOrInvoke);
5994 if (!PD->isInlineBuiltinDeclaration())
6003 std::string NoBuiltinFD = (
"no-builtin-" + FD->
getName()).str();
6004 std::string NoBuiltins =
"no-builtins";
6007 std::string FDInlineName = (Ident +
".inline").str();
6009 bool IsPredefinedLibFunction =
6011 bool HasAttributeNoBuiltin =
6012 CGF.
CurFn->getAttributes().hasFnAttr(NoBuiltinFD) ||
6013 CGF.
CurFn->getAttributes().hasFnAttr(NoBuiltins);
6017 if (CGF.
CurFn->getName() != FDInlineName &&
6020 llvm::Function *Fn = llvm::cast<llvm::Function>(CalleePtr);
6021 llvm::Module *M = Fn->getParent();
6022 llvm::Function *Clone = M->getFunction(FDInlineName);
6024 Clone = llvm::Function::Create(Fn->getFunctionType(),
6025 llvm::GlobalValue::InternalLinkage,
6026 Fn->getAddressSpace(), FDInlineName, M);
6027 Clone->addFnAttr(llvm::Attribute::AlwaysInline);
6038 else if (!IsPredefinedLibFunction || !HasAttributeNoBuiltin)
6044 FD->
hasAttr<CUDAGlobalAttr>())
6052 if (DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()))
6061 if (
auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
6062 if (ICE->getCastKind() == CK_FunctionToPointerDecay ||
6063 ICE->getCastKind() == CK_BuiltinFnToFnPtr) {
6069 if (ICE->getCastKind() == CK_LValueToRValue) {
6070 const Expr *SubExpr = ICE->getSubExpr();
6072 std::pair<llvm::Value *, CGPointerAuthInfo>
Result =
6079 if (
const auto *VD =
6090 }
else if (
auto DRE = dyn_cast<DeclRefExpr>(E)) {
6091 if (
auto FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
6094 }
else if (
auto ME = dyn_cast<MemberExpr>(E)) {
6095 if (
auto FD = dyn_cast<FunctionDecl>(ME->getMemberDecl())) {
6101 }
else if (
auto NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
6105 }
else if (
auto PDE = dyn_cast<CXXPseudoDestructorExpr>(E)) {
6110 llvm::Value *calleePtr;
6122 if (
const auto *VD =
6128 CGCallee callee(calleeInfo, calleePtr, pointerAuth);
6144 assert(E->
getOpcode() == BO_Assign &&
"unexpected binary l-value");
6207 llvm::Value *
Result =
nullptr;
6210 if (
SanOpts.has(SanitizerKind::ImplicitBitfieldConversion))
6225 CGM.getOpenMPRuntime().checkAndEmitLastprivateConditional(*
this,
6242 llvm_unreachable(
"bad evaluation kind");
6258 llvm::CallBase **CallOrInvoke) {
6266 "Can't have a scalar return unless the return type is a "
6279 &&
"binding l-value to type which needs a temporary");
6317 "Can't have a scalar return unless the return type is a "
6331 return CGM.getObjCRuntime().EmitIvarOffset(*
this,
Interface, Ivar);
6339 return Builder.CreateZExtOrTrunc(OffsetValue,
6344 llvm::Value *BaseValue,
6346 unsigned CVRQualifiers) {
6347 return CGM.getObjCRuntime().EmitObjCValueForIvar(*
this, ObjectTy, BaseValue,
6348 Ivar, CVRQualifiers);
6353 llvm::Value *BaseValue =
nullptr;
6364 ObjectTy = BaseExpr->
getType();
6386 llvm::CallBase **CallOrInvoke,
6391 "Call must have function pointer type!");
6393 const Decl *TargetDecl =
6396 assert((!isa_and_present<FunctionDecl>(TargetDecl) ||
6398 "trying to emit a call to an immediate function");
6406 if (
SanOpts.has(SanitizerKind::Function) &&
6409 if (llvm::Constant *PrefixSig =
6410 CGM.getTargetCodeGenInfo().getUBSanFunctionSignature(
CGM)) {
6411 auto CheckOrdinal = SanitizerKind::SO_Function;
6412 auto CheckHandler = SanitizerHandler::FunctionTypeMismatch;
6416 llvm::Type *PrefixSigType = PrefixSig->getType();
6417 llvm::StructType *PrefixStructTy = llvm::StructType::get(
6418 CGM.getLLVMContext(), {PrefixSigType, Int32Ty},
true);
6420 llvm::Value *CalleePtr = Callee.getFunctionPointer();
6421 if (
CGM.getCodeGenOpts().PointerAuth.FunctionPointers) {
6424 Address(CalleePtr, CalleePtr->getType(),
6426 CalleePtr->getPointerAlignment(
CGM.getDataLayout())),
6427 Callee.getPointerAuthInfo(),
nullptr);
6428 CalleePtr =
Addr.emitRawPointer(*
this);
6440 llvm::Value *AlignedCalleePtr;
6441 if (
CGM.getTriple().isARM() ||
CGM.getTriple().isThumb()) {
6442 llvm::Value *CalleeAddress =
6444 llvm::Value *Mask = llvm::ConstantInt::get(
IntPtrTy, ~1);
6445 llvm::Value *AlignedCalleeAddress =
6446 Builder.CreateAnd(CalleeAddress, Mask);
6448 Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());
6450 AlignedCalleePtr = CalleePtr;
6453 llvm::Value *CalleePrefixStruct = AlignedCalleePtr;
6454 llvm::Value *CalleeSigPtr =
6455 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 0);
6456 llvm::Value *CalleeSig =
6458 llvm::Value *CalleeSigMatch =
Builder.CreateICmpEQ(CalleeSig, PrefixSig);
6462 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
6465 llvm::Value *CalleeTypeHash =
Builder.CreateAlignedLoad(
6467 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 1),
6469 llvm::Value *CalleeTypeHashMatch =
6470 Builder.CreateICmpEQ(CalleeTypeHash, TypeHash);
6473 EmitCheck(std::make_pair(CalleeTypeHashMatch, CheckOrdinal), CheckHandler,
6474 StaticData, {CalleePtr});
6483 if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
6484 FD && DeviceKernelAttr::isOpenCLSpelling(FD->getAttr<DeviceKernelAttr>()))
6485 CGM.getTargetCodeGenInfo().setOCLKernelStubCallingConvention(FnType);
6492 if (
SanOpts.has(SanitizerKind::CFIICall) &&
6494 auto CheckOrdinal = SanitizerKind::SO_CFIICall;
6495 auto CheckHandler = SanitizerHandler::CFICheckFail;
6499 llvm::Metadata *MD =
6500 CGM.CreateMetadataIdentifierForFnType(
QualType(FnType, 0));
6502 llvm::Value *TypeId = llvm::MetadataAsValue::get(
getLLVMContext(), MD);
6504 llvm::Value *CalleePtr = Callee.getFunctionPointer();
6505 llvm::Value *TypeTest =
Builder.CreateCall(
6506 CGM.getIntrinsic(llvm::Intrinsic::type_test), {CalleePtr, TypeId});
6508 auto CrossDsoTypeId =
CGM.CreateCrossDsoCfiTypeId(MD);
6509 llvm::Constant *StaticData[] = {
6514 if (
CGM.getCodeGenOpts().SanitizeCfiCrossDso && CrossDsoTypeId) {
6518 EmitCheck(std::make_pair(TypeTest, CheckOrdinal), CheckHandler,
6519 StaticData, {CalleePtr, llvm::UndefValue::get(
IntPtrTy)});
6534 bool StaticOperator =
false;
6535 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
6536 if (OCE->isAssignmentOp())
6539 switch (OCE->getOperator()) {
6541 case OO_GreaterGreater:
6553 if (
const auto *MD =
6554 dyn_cast_if_present<CXXMethodDecl>(OCE->getCalleeDecl());
6555 MD && MD->isStatic())
6556 StaticOperator =
true;
6560 if (StaticOperator) {
6564 Arguments = drop_begin(Arguments, 1);
6566 EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), Arguments,
6570 Args, FnType, Chain);
6573 *ResolvedFnInfo = &FnInfo;
6578 if (
CGM.getLangOpts().HIP && !
CGM.getLangOpts().CUDAIsDevice &&
6581 llvm::Value *Handle = Callee.getFunctionPointer();
6583 Address(Handle, Handle->getType(),
CGM.getPointerAlign()));
6584 Callee.setFunctionPointer(
Stub);
6586 llvm::CallBase *LocalCallOrInvoke =
nullptr;
6593 if (
auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
6596 DI->EmitFuncDeclForCallSite(LocalCallOrInvoke,
6597 DI->getFunctionType(CalleeDecl, ResTy, Args),
6602 *CallOrInvoke = LocalCallOrInvoke;
6621 bool IsInBounds = !
getLangOpts().PointerOverflowDefined &&
6624 E, BaseAddr, OffsetV, MPT, IsInBounds, &BaseInfo, &TBAAInfo);
6626 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
6643 llvm_unreachable(
"bad evaluation kind");
6647 assert(Val->getType()->isFPOrFPVectorTy());
6652 llvm::MDNode *Node = MDHelper.createFPMath(Accuracy);
6658 llvm::Type *EltTy = Val->getType()->getScalarType();
6659 if (!EltTy->isFloatTy())
6663 !
CGM.getCodeGenOpts().OpenCLCorrectlyRoundedDivSqrt) ||
6665 !
CGM.getCodeGenOpts().HIPCorrectlyRoundedDivSqrt)) {
6679 llvm::Type *EltTy = Val->getType()->getScalarType();
6680 if (!EltTy->isFloatTy())
6684 !
CGM.getCodeGenOpts().OpenCLCorrectlyRoundedDivSqrt) ||
6686 !
CGM.getCodeGenOpts().HIPCorrectlyRoundedDivSqrt)) {
6700 struct LValueOrRValue {
6714 LValueOrRValue result;
6718 const Expr *semantic = *i;
6722 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
6724 if (ov->isUnique()) {
6725 assert(ov != resultExpr &&
6726 "A unique OVE cannot be used as the result expression");
6734 if (ov == resultExpr && ov->
isPRValue() && !forLValue &&
6739 opaqueData = OVMA::bind(CGF, ov, LV);
6744 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
6747 if (ov == resultExpr) {
6755 opaques.push_back(opaqueData);
6759 }
else if (semantic == resultExpr) {
6796 llvm::IntegerType *IdxTy = llvm::IntegerType::get(
getLLVMContext(), 32);
6798 WorkList.push_back({AddrType, {llvm::ConstantInt::get(IdxTy, 0)}});
6800 while (!WorkList.empty()) {
6801 auto [
T, IdxList] = WorkList.pop_back_val();
6802 T =
T.getCanonicalType().getUnqualifiedType();
6804 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
T)) {
6805 uint64_t Size = CAT->getZExtSize();
6806 for (int64_t I = Size - 1; I > -1; I--) {
6808 IdxListCopy.push_back(llvm::ConstantInt::get(IdxTy, I));
6809 WorkList.emplace_back(CAT->getElementType(), IdxListCopy);
6811 }
else if (
const auto *RT = dyn_cast<RecordType>(
T)) {
6813 assert(!
Record->isUnion() &&
"Union types not supported in flat cast.");
6824 FieldTypes.push_back(
Base.getType());
6827 for (
auto *FD :
Record->fields())
6828 FieldTypes.push_back(FD->getType());
6830 for (int64_t I = FieldTypes.size() - 1; I > -1; I--) {
6832 IdxListCopy.push_back(llvm::ConstantInt::get(IdxTy, I));
6833 WorkList.insert(WorkList.end(), {FieldTypes[I], IdxListCopy});
6835 }
else if (
const auto *VT = dyn_cast<VectorType>(
T)) {
6839 Builder.CreateInBoundsGEP(
Addr, IdxList, LLVMT, Align,
"vector.gep");
6840 for (
unsigned I = 0, E = VT->getNumElements(); I < E; I++) {
6841 llvm::Value *Idx = llvm::ConstantInt::get(IdxTy, I);
6844 AccessList.emplace_back(GEP, Idx);
6845 FlatTypes.push_back(VT->getElementType());
6852 Builder.CreateInBoundsGEP(
Addr, IdxList, LLVMT, Align,
"gep");
6853 AccessList.emplace_back(GEP,
nullptr);
6854 FlatTypes.push_back(
T);
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, LValue &LV, bool IsMemberAccess=false)
static LValue EmitGlobalNamedRegister(const VarDecl *VD, CodeGenModule &CGM)
Named Registers are named metadata pointing to the register name which will be read from/written to a...
static llvm::Value * emitHashMix(CGBuilderTy &Builder, llvm::Value *Acc, llvm::Value *Ptr)
static const Expr * isSimpleArrayDecayOperand(const Expr *E)
isSimpleArrayDecayOperand - If the specified expr is a simple decay from an array to pointer,...
static bool getFieldOffsetInBits(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *Field, int64_t &Offset)
The offset of a field from the beginning of the record.
static bool hasBPFPreserveStaticOffset(const RecordDecl *D)
ConstantEmissionKind
Can we constant-emit a load of a reference to a variable of the given type?
static bool isConstantEmittableObjectType(QualType type)
Given an object of the given canonical type, can we safely copy a value out of it based on its initia...
static LValue EmitCapturedFieldLValue(CodeGenFunction &CGF, const FieldDecl *FD, llvm::Value *ThisValue)
static std::optional< LValue > EmitLValueOrThrowExpression(CodeGenFunction &CGF, const Expr *Operand)
Emit the operand of a glvalue conditional operator.
static CheckRecoverableKind getRecoverableKind(SanitizerKind::SanitizerOrdinal Ordinal)
static llvm::Value * emitArraySubscriptGEP(CodeGenFunction &CGF, llvm::Type *elemType, llvm::Value *ptr, ArrayRef< llvm::Value * > indices, bool inbounds, bool signedIndices, SourceLocation loc, const llvm::Twine &name="arrayidx")
SmallVector< llvm::Value *, 8 > RecIndicesTy
static GlobalDecl getGlobalDeclForDirectCall(const FunctionDecl *FD)
static LValue EmitFunctionDeclLValue(CodeGenFunction &CGF, const Expr *E, GlobalDecl GD)
static RawAddress MaybeConvertMatrixAddress(RawAddress Addr, CodeGenFunction &CGF, bool IsVector=true)
static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF, const PseudoObjectExpr *E, bool forLValue, AggValueSlot slot)
static Address wrapWithBPFPreserveStaticOffset(CodeGenFunction &CGF, Address &Addr)
static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID)
static llvm::Value * getArrayIndexingBound(CodeGenFunction &CGF, const Expr *Base, QualType &IndexedType, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel)
If Base is known to point to the start of an array, return the length of that array.
static RValue EmitLoadOfMatrixLValue(LValue LV, SourceLocation Loc, CodeGenFunction &CGF)
static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type)
static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base, const FieldDecl *Field, bool IsInBounds)
Get the address of a zero-sized field within a record.
static QualType getConstantExprReferredType(const FullExpr *E, const ASTContext &Ctx)
static Address emitAddrOfFieldStorage(CodeGenFunction &CGF, Address base, const FieldDecl *field, bool IsInBounds)
Drill down to the storage of a field without walking into reference types.
static bool getRangeForType(CodeGenFunction &CGF, QualType Ty, llvm::APInt &Min, llvm::APInt &End, bool StrictEnums, bool IsBool)
static std::optional< int64_t > getOffsetDifferenceInBits(CodeGenFunction &CGF, const FieldDecl *FD1, const FieldDecl *FD2)
Returns the relative offset difference between FD1 and FD2.
static CGCallee EmitDirectCallee(CodeGenFunction &CGF, GlobalDecl GD)
static LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc)
static bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *Field, RecIndicesTy &Indices)
static bool OnlyHasInlineBuiltinDeclaration(const FunctionDecl *FD)
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD)
static bool hasAnyVptr(const QualType Type, const ASTContext &Context)
static bool IsPreserveAIArrayBase(CodeGenFunction &CGF, const Expr *ArrayBase)
Given an array base, check whether its member access belongs to a record with preserve_access_index a...
static Address emitDeclTargetVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T)
static bool canEmitSpuriousReferenceToVariable(CodeGenFunction &CGF, const DeclRefExpr *E, const VarDecl *VD)
Determine whether we can emit a reference to VD from the current context, despite not necessarily hav...
VariableTypeDescriptorKind
@ TK_Float
A floating-point type.
@ TK_Unknown
Any other type. The value representation is unspecified.
@ TK_Integer
An integer type.
@ TK_BitInt
An _BitInt(N) type.
static void EmitStoreOfMatrixScalar(llvm::Value *value, LValue lvalue, bool isInit, CodeGenFunction &CGF)
static Address EmitPointerWithAlignment(const Expr *E, LValueBaseInfo *BaseInfo, TBAAAccessInfo *TBAAInfo, KnownNonNull_t IsKnownNonNull, CodeGenFunction &CGF)
static Address emitPreserveStructAccess(CodeGenFunction &CGF, LValue base, Address addr, const FieldDecl *field)
const SanitizerHandlerInfo SanitizerHandlers[]
static void emitCheckHandlerCall(CodeGenFunction &CGF, llvm::FunctionType *FnType, ArrayRef< llvm::Value * > FnArgs, SanitizerHandler CheckHandler, CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB, bool NoMerge)
static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base, LValueBaseInfo &BaseInfo, TBAAAccessInfo &TBAAInfo, QualType BaseTy, QualType ElTy, bool IsLowerBound)
static mlir::Value emitPointerArithmetic(CIRGenFunction &cgf, const BinOpInfo &op, bool isSubtraction)
Emit pointer + index arithmetic.
static Address createReferenceTemporary(CIRGenFunction &cgf, const MaterializeTemporaryExpr *m, const Expr *inner)
static bool isAAPCS(const TargetInfo &targetInfo)
Helper method to check if the underlying ABI is AAPCS.
static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx, CharUnits eltSize)
static void pushTemporaryCleanup(CIRGenFunction &cgf, const MaterializeTemporaryExpr *m, const Expr *e, Address referenceTemporary)
static QualType getFixedSizeElementType(const ASTContext &astContext, const VariableArrayType *vla)
static DeclRefExpr * tryToConvertMemberExprToDeclRefExpr(CIRGenFunction &cgf, const MemberExpr *me)
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
llvm::MachO::Record Record
Defines the clang::Module class, which describes a module in the source code.
static const SanitizerMask AlwaysRecoverable
static const SanitizerMask Unrecoverable
#define LIST_SANITIZER_CHECKS
Defines the SourceManager interface.
static QualType getPointeeType(const MemRegion *R)
a trap message and trap category.
const LValueBase getLValueBase() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Builtin::Context & BuiltinInfo
const LangOptions & getLangOpts() const
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
llvm::DenseMap< const CXXMethodDecl *, CXXCastPath > LambdaCastPaths
For capturing lambdas with an explicit object parameter whose type is derived from the lambda type,...
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
bool isSentinelNullExpr(const Expr *E)
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Expr * getBase()
Get base of the array section.
Expr * getLength()
Get length of array section.
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
SourceLocation getExprLoc() const LLVM_READONLY
Expr * getLowerBound()
Get lower bound of array section.
bool isOpenACCArraySection() const
SourceLocation getColonLocFirst() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
SourceLocation getExprLoc() const LLVM_READONLY
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getExprLoc() const
static bool isAdditiveOp(Opcode Opc)
A fixed int type of a specified bitwidth.
unsigned getNumBits() const
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Represents binding an expression to a temporary.
CXXTemporary * getTemporary()
const Expr * getSubExpr() const
Represents a call to a C++ constructor.
Represents a C++ destructor within a class.
Represents a C++ struct/union/class.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
bool isStandardLayout() const
Determine whether this class is standard-layout per C++ [class]p7.
bool isDynamicClass() const
bool hasDefinition() const
const CXXRecordDecl * getStandardLayoutBaseWithFields() const
If this is a standard-layout class or union, any and all data members will be declared in the same ty...
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
MSGuidDecl * getGuidDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
SourceLocation getBeginLoc() const
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
bool isCoroElideSafe() const
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
path_iterator path_begin()
CastKind getCastKind() const
bool changesVolatileQualification() const
Return.
CharUnits - This is an opaque type for sizes expressed in character units.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
llvm::MaybeAlign getAsMaybeAlign() const
getAsMaybeAlign - Returns Quantity as a valid llvm::Align or std::nullopt, Beware llvm::MaybeAlign as...
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
@ None
Trap Messages are omitted.
@ Detailed
Trap Message includes more context (e.g.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withPointer(llvm::Value *NewPointer, KnownNonNull_t IsKnownNonNull) const
Return address with different pointer, but same element type and alignment.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::PointerType * getType() const
Return the type of the pointer value.
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Address getAddress() const
void setExternallyDestructed(bool destructed=true)
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
A scoped helper to set the current source atom group for CGDebugInfo::addInstToCurrentSourceAtom.
A scoped helper to set the current debug location to the specified location or preferred location of ...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Address CreateConstGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ... produce name = getelementptr inbounds addr, i64 0, i64 index where i64 is a...
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Address CreateConstByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Address CreatePreserveStructAccessIndex(Address Addr, unsigned Index, unsigned FieldIndex, llvm::MDNode *DbgInfo)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
virtual llvm::Function * getKernelStub(llvm::GlobalValue *Handle)=0
Get kernel stub by kernel handle.
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
Emit a reference to a non-local thread_local variable (including triggering the initialization of all...
virtual bool usesThreadWrapperFunction(const VarDecl *VD) const =0
Abstract information about a function or function prototype.
const GlobalDecl getCalleeDecl() const
All available information about a concrete callee.
CGCalleeInfo getAbstractInfo() const
const CXXPseudoDestructorExpr * getPseudoDestructorExpr() const
bool isPseudoDestructor() const
static CGCallee forBuiltin(unsigned builtinID, const FunctionDecl *builtinDecl)
unsigned getBuiltinID() const
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
const FunctionDecl * getBuiltinDecl() const
static CGCallee forPseudoDestructor(const CXXPseudoDestructorExpr *E)
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
llvm::DILocation * CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg)
Create a debug location from TrapLocation that adds an artificial inline frame where the frame name i...
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
CGFunctionInfo - Class to encapsulate the information about a function definition.
virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
virtual ConstantAddress getAddrOfDeclareTargetVar(const VarDecl *VD)
Returns the address of the variable marked as declare target with link clause OR as declare target wi...
bool hasRequiresUnifiedSharedMemory() const
Return whether the unified_shared_memory has been specified.
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
bool containsFieldDecl(const FieldDecl *FD) const
CallArgList - Type for representing both the value and type of arguments in a call.
void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse, const Expr *writebackExpr=nullptr)
void add(RValue rvalue, QualType type)
The scope of a CXXDefaultInitExpr.
An object to manage conditionally-evaluated expressions.
llvm::BasicBlock * getStartingBlock() const
Returns a block which will be executed prior to each evaluation of the conditional code.
static ConstantEmission forValue(llvm::Constant *C)
static ConstantEmission forReference(llvm::Constant *C)
LValue getReferenceLValue(CodeGenFunction &CGF, const Expr *RefExpr) const
llvm::Constant * getValue() const
A non-RAII class containing all the information about a bound opaque value.
static bool shouldBindAsLValue(const Expr *expr)
static OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e)
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
static bool shouldBindAsLValue(const Expr *expr)
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E)
LValue EmitCoawaitLValue(const CoawaitExpr *E)
llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass, VTableAuthMode AuthMode=VTableAuthMode::Authenticate)
GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
Produce the code for a CK_ARCConsumeObject.
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr, const VarDecl *ConditionalDecl=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
llvm::Value * emitBoolVecConversion(llvm::Value *SrcVec, unsigned NumElementsDst, const llvm::Twine &Name="")
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E)
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
void SetDivFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
SanitizerSet SanOpts
Sanitizers enabled for this function.
LValue EmitInitListLValue(const InitListExpr *E)
bool isUnderlyingBasePointerConstantNull(const Expr *E)
Check whether the underlying base pointer is a constant null.
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
RawAddress CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
Address LoadCXXThisAddress()
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
llvm::Value * GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD, const FieldDecl *CountDecl)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
llvm::Type * ConvertType(QualType T)
Address EmitCXXUuidofExpr(const CXXUuidofExpr *E)
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
static Destroyer destroyARCWeak
CGCapturedStmtInfo * CapturedStmtInfo
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
bool inSuspendBlock() const
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
Produce the code to do a retain.
llvm::Value * EmitPointerAuthQualify(PointerAuthQualifier Qualifier, llvm::Value *Pointer, QualType ValueType, Address StorageAddress, bool IsKnownNonNull)
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src, ExprValueKind SrcKind)
EmitAggFinalDestCopy - Emit copy of the specified aggregate into destination address.
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst)
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Given the address of a temporary variable, produce an r-value of its type.
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
void SetSqrtFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)
Emit a CallExpr without considering whether it might be a subclass.
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
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.
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex)
Get the record field index as represented in debug info.
const LangOptions & getLangOpts() const
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
Store into a strong object.
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E)
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc)
Given an assignment *LHS = RHS, emit a test that checks if RHS is nonnull, if LHS is marked _Nonnull.
llvm::Value * EmitPointerAuthUnqualify(PointerAuthQualifier Qualifier, llvm::Value *Pointer, QualType PointerType, Address StorageAddress, bool IsKnownNonNull)
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
Address makeNaturalAddressForPointer(llvm::Value *Ptr, QualType T, CharUnits Alignment=CharUnits::Zero(), bool ForPointeeType=false, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
Construct an address with the natural alignment of T.
static Destroyer destroyCXXObject
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Load a pointer with type PtrTy stored at address Ptr.
RValue EmitLoadOfGlobalRegLValue(LValue LV)
Load of global named registers are always calls to intrinsics.
void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull, CFITypeCheckKind TCK, SourceLocation Loc)
Derived is the presumed address of an object of type T after a cast.
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
@ TCK_DowncastPointer
Checking the operand of a static_cast to a derived pointer type.
@ TCK_DowncastReference
Checking the operand of a static_cast to a derived reference type.
@ TCK_MemberAccess
Checking the object expression in a non-static data member access.
@ TCK_Store
Checking the destination of a store. Must be suitably sized and aligned.
@ TCK_UpcastToVirtualBase
Checking the operand of a cast to a virtual base object.
@ TCK_MemberCall
Checking the 'this' pointer for a call to a non-static member function.
@ TCK_DynamicOperation
Checking the operand of a dynamic_cast or a typeid expression.
@ TCK_ReferenceBinding
Checking the bound value in a reference binding.
@ TCK_Upcast
Checking the operand of a cast to a base object.
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
bool InNoMergeAttributedStmt
True if the current statement has nomerge attribute.
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty, SourceLocation Loc)
void EmitBitfieldConversionCheck(llvm::Value *Src, QualType SrcType, llvm::Value *Dst, QualType DstType, const CGBitFieldInfo &Info, SourceLocation Loc)
Emit a check that an [implicit] conversion of a bitfield.
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::Value *Index, QualType IndexType, QualType IndexedType, bool Accessed)
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
llvm::Value * LoadPassedObjectSize(const Expr *E, QualType EltTy)
If E references a parameter with pass_object_size info or a constant array size modifier,...
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
@ Default
! No language constraints on evaluation order.
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
llvm::Value * EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
LValue EmitLValueForField(LValue Base, const FieldDecl *Field, bool IsInBounds=true)
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
const TargetInfo & getTarget() const
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, bool IsInBounds, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Emit the address of a field using a member data pointer.
LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args, QualType Ty)
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
CGCallee EmitCallee(const Expr *E)
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot(), llvm::CallBase **CallOrInvoke=nullptr)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
LValue EmitArraySectionExpr(const ArraySectionExpr *E, bool IsLowerBound=true)
Address GetAddrOfBlockDecl(const VarDecl *var)
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
void pushCleanupAfterFullExpr(CleanupKind Kind, As... A)
Queue a cleanup to be pushed after finishing the current full-expression, potentially with an active ...
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
void pushFullExprCleanup(CleanupKind kind, As... A)
pushFullExprCleanup - Push a cleanup to be run at the end of the current full-expression.
static Destroyer destroyARCStrongImprecise
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
void SetFPAccuracy(llvm::Value *Val, float Accuracy)
SetFPAccuracy - Set the minimum required accuracy of the given floating point operation,...
Address mergeAddressesInConditionalExpr(Address LHS, Address RHS, llvm::BasicBlock *LHSBlock, llvm::BasicBlock *RHSBlock, llvm::BasicBlock *MergeBlock, QualType MergedType)
Address emitAddrOfImagComponent(Address complex, QualType complexType)
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
LValue EmitPredefinedLValue(const PredefinedExpr *E)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerKind::SanitizerOrdinal > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs, const TrapReason *TR=nullptr)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
LValue EmitDeclRefLValue(const DeclRefExpr *E)
LValue EmitStringLiteralLValue(const StringLiteral *E)
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
CGDebugInfo * getDebugInfo()
llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
bool EmitLifetimeStart(llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
LValue EmitUnsupportedLValue(const Expr *E, const char *Name)
EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...
LValue MakeRawAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, AlignmentSource Source=AlignmentSource::Type)
Same as MakeAddrLValue above except that the pointer is known to be unsigned.
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward=true)
BuildBlockByrefAddress - Computes the location of the data in a variable which is declared as __block...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, SourceLocation Loc)
Check if the scalar Value is within the valid range for the given type Ty.
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
const TargetCodeGenInfo & getTargetHooks() const
llvm::ConstantInt * getUBSanFunctionTypeHash(QualType T) const
Return a type hash constant for a function instrumented by -fsanitize=function.
LValue EmitHLSLArrayAssignLValue(const BinaryOperator *E)
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
LValue EmitVAArgExprLValue(const VAArgExpr *E)
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
LValue EmitStmtExprLValue(const StmtExpr *E)
llvm::Value * EmitARCLoadWeakRetained(Address addr)
i8* @objc_loadWeakRetained(i8** addr)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
llvm::Value * EmitWithOriginalRHSBitfieldAssignment(const BinaryOperator *E, llvm::Value **Previous, QualType *SrcType)
Retrieve the implicit cast expression of the rhs in a binary operator expression by passing pointers ...
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
llvm::Instruction * getPostAllocaInsertPoint()
Return PostAllocaInsertPt.
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
LValue EmitCastLValue(const CastExpr *E)
EmitCastLValue - Casts are never lvalues unless that cast is to a reference type.
llvm::Value * EmitPointerArithmetic(const BinaryOperator *BO, Expr *pointerOperand, llvm::Value *pointer, Expr *indexOperand, llvm::Value *index, bool isSubtraction)
Emit pointer + index arithmetic.
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E)
llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields
RValue EmitUnsupportedRValue(const Expr *E, const char *Name)
EmitUnsupportedRValue - Emit a dummy r-value using the type of E and issue an ErrorUnsupported style ...
CleanupKind getCleanupKind(QualType::DestructionKind kind)
std::pair< LValue, LValue > EmitHLSLOutArgLValues(const HLSLOutArgExpr *E, QualType Ty)
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
llvm::Type * ConvertTypeForMem(QualType T)
LValue EmitCallExprLValue(const CallExpr *E, llvm::CallBase **CallOrInvoke=nullptr)
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
llvm::Value * EmitARCLoadWeak(Address addr)
i8* @objc_loadWeak(i8** addr) Essentially objc_autorelease(objc_loadWeakRetained(addr)).
LValue EmitLValueForLambdaField(const FieldDecl *Field)
void markStmtMaybeUsed(const Stmt *S)
CodeGenTypes & getTypes() const
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
llvm::Value * EmitIvarOffset(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, LValue LV, QualType Type, SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
void EmitCfiSlowPathCheck(SanitizerKind::SanitizerOrdinal Ordinal, llvm::Value *Cond, llvm::ConstantInt *TypeId, llvm::Value *Ptr, ArrayRef< llvm::Constant * > StaticArgs)
Emit a slow path cross-DSO CFI check which calls __cfi_slowpath if Cond if false.
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
llvm::Value * authPointerToPointerCast(llvm::Value *ResultPtr, QualType SourceType, QualType DestType)
LValue EmitUnaryOpLValue(const UnaryOperator *E)
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
llvm::Type * convertTypeForLoadStore(QualType ASTTy, llvm::Type *LLVMTy=nullptr)
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
Address EmitExtVectorElementLValue(LValue V)
Generates lvalue for partial ext_vector access.
llvm::Value * EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr, ArrayRef< llvm::Value * > IdxList, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, const Twine &Name="")
Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to detect undefined behavior whe...
void EmitInitializationToLValue(const Expr *E, LValue LV, AggValueSlot::IsZeroed_t IsZeroed=AggValueSlot::IsNotZeroed)
EmitInitializationToLValue - Emit an initializer to an LValue.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
Address emitAddrOfRealComponent(Address complex, QualType complexType)
void FlattenAccessAndType(Address Addr, QualType AddrTy, SmallVectorImpl< std::pair< Address, llvm::Value * > > &AccessList, SmallVectorImpl< QualType > &FlatTypes)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
RValue EmitLoadOfExtVectorElementLValue(LValue V)
static bool hasAggregateEvaluationKind(QualType T)
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
llvm::Value * EmitMatrixIndexExpr(const Expr *E)
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, bool NoMerge=false, const TrapReason *TR=nullptr)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
const CallExpr * MustTailCall
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
llvm::Value * EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FD, const FieldDecl *CountDecl)
Build an expression accessing the "counted_by" field.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E)
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
generateDestroyHelper - Generates a helper function which, when invoked, destroys the given object.
LValue EmitMemberExpr(const MemberExpr *E)
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
ConstantEmission tryEmitAsConstant(const DeclRefExpr *RefExpr)
Try to emit a reference to the given value without producing it as an l-value.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Store of global named registers are always calls to intrinsics.
bool isOpaqueValueEmitted(const OpaqueValueExpr *E)
isOpaqueValueEmitted - Return true if the opaque value expression has already been emitted.
std::pair< llvm::Value *, CGPointerAuthInfo > EmitOrigPointerRValue(const Expr *E)
Retrieve a pointer rvalue and its ptrauth info.
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
i8* @objc_storeWeak(i8** addr, i8* value) Returns value.
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
llvm::LLVMContext & getLLVMContext()
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)
static Destroyer destroyARCStrongPrecise
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)
getAccessedFieldNo - Given an encoded value and a result number, return the input field number being ...
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...
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
llvm::Value * EmitNonNullRValueCheck(RValue RV, QualType T)
Create a check that a scalar RValue is non-null.
void EmitCountedByBoundsChecking(const Expr *E, llvm::Value *Idx, Address Addr, QualType IdxTy, QualType ArrayTy, bool Accessed, bool FlexibleArray)
EmitCountedByBoundsChecking - If the array being accessed has a "counted_by" attribute,...
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
This class organizes the cross-function state that is used while generating LLVM code.
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
llvm::Module & getModule() const
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CGDebugInfo * getModuleDebugInfo()
llvm::Constant * getRawFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return a function pointer for a reference to the given function.
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
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.
llvm::Constant * getFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return the ABI-correct function pointer value for a reference to the given function.
const LangOptions & getLangOpts() const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
CodeGenTypes & getTypes()
CGPointerAuthInfo getPointerAuthInfoForPointeeType(QualType type)
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
CGCXXABI & getCXXABI() const
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type.
ASTContext & getContext() const
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purposes of type casts.
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.
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
llvm::LLVMContext & getLLVMContext()
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys={})
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
A specialization of Address that requires the address to be an LLVM Constant.
llvm::Constant * getPointer() const
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
AlignmentSource getAlignmentSource() const
LValue - This represents an lvalue references.
Expr * getBaseIvarExp() const
llvm::Constant * getExtVectorElts() const
static LValue MakeGlobalReg(llvm::Value *V, CharUnits alignment, QualType type)
bool isObjCStrong() const
bool isGlobalObjCRef() const
bool isVolatileQualified() const
RValue asAggregateRValue() const
llvm::Value * getPointer(CodeGenFunction &CGF) const
llvm::Value * getMatrixIdx() const
llvm::Value * getGlobalReg() const
static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
const Qualifiers & getQuals() const
static LValue MakeExtVectorElt(Address Addr, llvm::Constant *Elts, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Address getAddress() const
unsigned getVRQualifiers() const
bool isExtVectorElt() const
llvm::Value * getVectorIdx() const
void setNontemporal(bool Value)
LValueBaseInfo getBaseInfo() const
void setARCPreciseLifetime(ARCPreciseLifetime_t value)
const CGBitFieldInfo & getBitFieldInfo() const
bool isThreadLocalRef() const
KnownNonNull_t isKnownNonNull() const
TBAAAccessInfo getTBAAInfo() const
void setNonGC(bool Value)
Address getVectorAddress() const
bool isNontemporal() const
static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Create a new object to represent a bit-field access.
static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
void setAddress(Address address)
Address getExtVectorAddress() const
static LValue MakeMatrixElt(Address matAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Address getMatrixAddress() const
Address getBitFieldAddress() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
An abstract representation of an aligned address.
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::Value * getPointer() const
unsigned getAddressSpace() const
Return the address space that this address resides in.
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, llvm::Type *DestTy, bool IsNonNull=false) const
StringRef getCategory() const
StringRef getMessage() const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumRows() const
Returns the number of rows in the matrix.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
A reference to a declared variable, function, enum, etc.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
SourceLocation getLocation() const
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
ExplicitCastExpr - An explicit cast written in the source code.
This represents one expression.
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...
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
Decl * getReferencedDeclOfCallee()
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
const Expr * getBase() const
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
FullExpr - Represents a "full-expression" node.
const Expr * getSubExpr() const
Represents a function declaration or definition.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Represents a prototype with parameter type info, e.g.
FunctionType - C99 6.7.5.3 - Function Declarators.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
This class represents temporary values used to represent inout and out arguments in HLSL.
const OpaqueValueExpr * getCastedTemporary() const
const OpaqueValueExpr * getOpaqueArgLValue() const
bool isInOut() const
returns true if the parameter is inout and false if the parameter is out.
const Expr * getWritebackCast() const
const Expr * getArgLValue() const
Return the l-value expression that was written as the argument in source.
Describes an C or C++ initializer list.
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
const Expr * getInit(unsigned Init) const
StrictFlexArraysLevelKind
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
bool isIncomplete() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
SourceLocation getExprLoc() const LLVM_READONLY
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool isObjCBOOLType(QualType T) const
Returns true if.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
A C++ nested-name-specifier augmented with source location information.
ObjCEncodeExpr, used for @encode in Objective-C.
Represents an ObjC class declaration.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
const Expr * getBase() const
An expression that sends a message to the given Objective-C object or class.
const ObjCMethodDecl * getMethodDecl() const
QualType getReturnType() const
ObjCSelectorExpr used for @selector in Objective-C.
Selector getSelector() const
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
const Expr * getSubExpr() const
Pointer-authentication qualifiers.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
StringRef getIdentKindName() const
PredefinedIdentKind getIdentKind() const
StringLiteral * getFunctionName()
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
semantics_iterator semantics_end()
semantics_iterator semantics_begin()
const Expr *const * const_semantics_iterator
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
PointerAuthQualifier getPointerAuth() const
QualType withoutLocalFastQualifiers() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
QualType withCVRQualifiers(unsigned CVR) const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void addCVRQualifiers(unsigned mask)
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
void setAddressSpace(LangAS space)
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
Represents a struct/union/class.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
StmtClass getStmtClass() const
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
Exposes information about the current target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual StringRef getABI() const
Get the ABI currently in use.
The base class of the type hierarchy.
bool isBlockPointerType() const
bool hasPointeeToToCFIUncheckedCalleeFunctionType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool isPackedVectorBoolType(const ASTContext &ctx) const
bool hasAttr(attr::Kind AK) const
Determine whether this type had the specified attribute applied to it (looking through top-level type...
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isConstantArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isFunctionPointerType() const
CXXRecordDecl * castAsCXXRecordDecl() const
bool isArithmeticType() const
bool isConstantMatrixType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
bool isVariableArrayType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isExtVectorBoolType() const
bool isBitIntType() const
bool isAnyComplexType() const
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isAtomicType() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isObjectType() const
Determine whether this type is an object type.
bool isHLSLResourceRecord() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isVectorType() const
bool isAnyPointerType() const
bool isSubscriptableVectorType() const
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isRecordType() const
bool isHLSLResourceRecordArray() const
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
bool isCFIUncheckedCalleeFunctionType() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
SourceLocation getExprLoc() const
Expr * getSubExpr() const
Represents a call to the builtin function __builtin_va_arg.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
TLSKind getTLSKind() const
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
@ TLS_Dynamic
TLS with a dynamic initializer.
@ TLS_None
Not a TLS variable.
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
unsigned getNumElements() const
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD)
isEmptyFieldForLayout - Return true iff the field is "empty", that is, either a zero-width bit-field ...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
static AlignmentSource getFieldAlignmentSource(AlignmentSource Source)
Given that the base address has the given alignment source, what's our confidence in the alignment of...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
const AstTypeMatcher< FunctionType > functionType
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
@ Asm
Assembly: we accept this only so that we can preprocess it.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
@ SD_Thread
Thread storage duration.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ SD_Automatic
Automatic storage duration (most local variables).
@ SD_Dynamic
Dynamic storage duration.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Dtor_Complete
Complete object dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
llvm::cl::opt< bool > ClSanitizeGuardChecks
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
U cast(CodeGen::Address addr)
LangAS getLangASFromTargetAS(unsigned TargetAS)
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
bool isLambdaMethod(const DeclContext *DC)
@ Other
Other implicit parameter.
@ NOUR_Unevaluated
This name appears in an unevaluated operand.
@ NOUR_Constant
This name appears as a potential result of an lvalue-to-rvalue conversion that is a constant expressi...
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
Structure with information about how a bitfield should be accessed.
CharUnits VolatileStorageOffset
The offset of the bitfield storage from the start of the struct.
unsigned VolatileOffset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned VolatileStorageSize
The storage size in bits which should be used when accessing this bitfield.
unsigned Size
The total size of the bit-field, in bits.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
unsigned IsSigned
Whether the bit-field is signed.
static Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int64Ty
CharUnits getIntAlign() const
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
llvm::IntegerType * SizeTy
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::PointerType * Int8PtrTy
llvm::PointerType * UnqualPtrTy
CharUnits getPointerAlign() const
LangAS getASTAllocaAddressSpace() const
llvm::MDNode * AccessType
AccessType - The final access type.
uint64_t Offset
Offset - The byte offset of the final access within the base one.
static TBAAAccessInfo getMayAliasInfo()
uint64_t Size
Size - The size of access, in bytes.
llvm::MDNode * BaseType
BaseType - The base/leading access type.
bool isIncomplete() const
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool HasSideEffects
Whether the evaluated expression has side effects.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
An adjustment to be made to the temporary created when emitting a reference binding,...
@ DerivedToBaseAdjustment
@ MemberPointerAdjustment