33#include "llvm/ADT/Hashing.h"
34#include "llvm/ADT/STLExtras.h"
35#include "llvm/ADT/StringExtras.h"
36#include "llvm/IR/DataLayout.h"
37#include "llvm/IR/Intrinsics.h"
38#include "llvm/IR/IntrinsicsWebAssembly.h"
39#include "llvm/IR/LLVMContext.h"
40#include "llvm/IR/MDBuilder.h"
41#include "llvm/IR/MatrixBuilder.h"
42#include "llvm/Passes/OptimizationLevel.h"
43#include "llvm/Support/ConvertUTF.h"
44#include "llvm/Support/MathExtras.h"
45#include "llvm/Support/Path.h"
46#include "llvm/Support/SaveAndRestore.h"
47#include "llvm/Support/xxhash.h"
48#include "llvm/Transforms/Utils/SanitizerStats.h"
54using namespace CodeGen;
58 "ubsan-unique-traps", llvm::cl::Optional,
59 llvm::cl::desc(
"Deoptimize traps for UBSAN so there is 1 trap per check."));
64 "ubsan-guard-checks", llvm::cl::Optional,
65 llvm::cl::desc(
"Guard UBSAN checks with `llvm.allow.ubsan.check()`."));
74CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty,
CharUnits Align,
76 llvm::Value *ArraySize) {
86 llvm::Value *ArraySize,
91 llvm::Value *
V = Alloca.getPointer();
98 llvm::IRBuilderBase::InsertPointGuard IPG(
Builder);
106 Ty->getPointerTo(DestAddrSpace),
true);
117 llvm::Value *ArraySize) {
119 return Builder.CreateAlloca(Ty, ArraySize, Name);
153 auto *ArrayTy = cast<llvm::ArrayType>(
Result.getElementType());
154 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),
155 ArrayTy->getNumElements());
186 CGFPOptionsRAII FPOptsRAII(*
this, E);
204 if (
const auto *CondOp = dyn_cast<AbstractConditionalOperator>(
227 if (!ignoreResult && aggSlot.
isIgnored())
232 llvm_unreachable(
"bad evaluation kind");
274 llvm_unreachable(
"bad evaluation kind");
315 VD && isa<VarDecl>(VD) && VD->
hasAttr<ObjCPreciseLifetimeAttr>();
336 llvm_unreachable(
"temporary cannot have dynamic storage duration");
338 llvm_unreachable(
"unknown storage duration");
346 auto *ClassDecl = cast<CXXRecordDecl>(RT->getDecl());
347 if (!ClassDecl->hasTrivialDestructor())
348 ReferenceTemporaryDtor = ClassDecl->getDestructor();
351 if (!ReferenceTemporaryDtor)
358 llvm::FunctionCallee CleanupFn;
359 llvm::Constant *CleanupArg;
362 ReferenceTemporary, E->
getType(),
365 CleanupArg = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
369 CleanupArg = cast<llvm::Constant>(ReferenceTemporary.
emitRawPointer(CGF));
384 ReferenceTemporary, E->
getType(),
390 llvm_unreachable(
"temporary cannot have dynamic storage duration");
412 auto *GV =
new llvm::GlobalVariable(
414 llvm::GlobalValue::PrivateLinkage,
Init,
".ref.tmp",
nullptr,
415 llvm::GlobalValue::NotThreadLocal,
419 llvm::Constant *
C = GV;
421 C = TCG.performAddrSpaceCast(
423 GV->getValueType()->getPointerTo(
426 return RawAddress(
C, GV->getValueType(), alignment);
435 llvm_unreachable(
"temporary can't have dynamic storage duration");
437 llvm_unreachable(
"unknown storage duration");
451 "Reference should never be pseudo-strong!");
459 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(
Object.getPointer())) {
469 if (Var->hasInitializer())
478 default: llvm_unreachable(
"expected scalar or aggregate expression");
501 for (
const auto &Ignored : CommaLHSs)
504 if (
const auto *opaque = dyn_cast<OpaqueValueExpr>(E)) {
505 if (opaque->getType()->isRecordType()) {
506 assert(Adjustments.empty());
514 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(
515 Object.getPointer()->stripPointerCasts())) {
521 if (!Var->hasInitializer()) {
537 if (!ShouldEmitLifetimeMarkers)
547 ConditionalEvaluation *OldConditional =
nullptr;
548 CGBuilderTy::InsertPoint OldIP;
554 OldConditional = OutermostConditional;
555 OutermostConditional =
nullptr;
558 llvm::BasicBlock *
Block = OldConditional->getStartingBlock();
559 Builder.restoreIP(CGBuilderTy::InsertPoint(
560 Block, llvm::BasicBlock::iterator(
Block->back())));
570 if (OldConditional) {
571 OutermostConditional = OldConditional;
588 switch (Adjustment.Kind) {
592 Adjustment.DerivedToBase.BasePath->path_begin(),
593 Adjustment.DerivedToBase.BasePath->path_end(),
601 "materialized temporary field is not a simple lvalue");
642 const llvm::Constant *Elts) {
643 return cast<llvm::ConstantInt>(Elts->getAggregateElement(Idx))
650 llvm::Value *KMul = Builder.getInt64(0x9ddfea08eb382d69ULL);
651 llvm::Value *K47 = Builder.getInt64(47);
652 llvm::Value *A0 = Builder.CreateMul(Builder.CreateXor(Low, High), KMul);
653 llvm::Value *A1 = Builder.CreateXor(Builder.CreateLShr(A0, K47), A0);
654 llvm::Value *B0 = Builder.CreateMul(Builder.CreateXor(High, A1), KMul);
655 llvm::Value *B1 = Builder.CreateXor(Builder.CreateLShr(B0, K47), B0);
656 return Builder.CreateMul(B1, KMul);
683 llvm::Value *ArraySize) {
690 if (Ptr->getType()->getPointerAddressSpace())
698 SanitizerScope SanScope(
this);
701 llvm::BasicBlock *Done =
nullptr;
706 auto PtrToAlloca = dyn_cast<llvm::AllocaInst>(Ptr->stripPointerCasts());
709 llvm::Value *IsNonNull =
nullptr;
710 bool IsGuaranteedNonNull =
711 SkippedChecks.
has(SanitizerKind::Null) || PtrToAlloca;
713 if ((
SanOpts.
has(SanitizerKind::Null) || AllowNullPointers) &&
714 !IsGuaranteedNonNull) {
716 IsNonNull =
Builder.CreateIsNotNull(Ptr);
720 IsGuaranteedNonNull = IsNonNull == True;
723 if (!IsGuaranteedNonNull) {
724 if (AllowNullPointers) {
729 Builder.CreateCondBr(IsNonNull, Rest, Done);
732 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null));
738 !SkippedChecks.
has(SanitizerKind::ObjectSize) &&
741 llvm::Value *
Size = llvm::ConstantInt::get(
IntPtrTy, TySize);
746 llvm::Constant *ConstantSize = dyn_cast<llvm::Constant>(Size);
747 if (!ConstantSize || !ConstantSize->isNullValue()) {
753 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::objectsize, Tys);
755 llvm::Value *NullIsUnknown =
Builder.getFalse();
757 llvm::Value *LargeEnough =
Builder.CreateICmpUGE(
758 Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic}), Size);
759 Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
763 llvm::MaybeAlign AlignVal;
764 llvm::Value *PtrAsInt =
nullptr;
767 !SkippedChecks.
has(SanitizerKind::Alignment)) {
775 if (AlignVal && *AlignVal > llvm::Align(1) &&
776 (!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {
778 llvm::Value *Align =
Builder.CreateAnd(
779 PtrAsInt, llvm::ConstantInt::get(
IntPtrTy, AlignVal->value() - 1));
780 llvm::Value *Aligned =
783 Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
787 if (Checks.size() > 0) {
788 llvm::Constant *StaticData[] = {
790 llvm::ConstantInt::get(
Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),
791 llvm::ConstantInt::get(
Int8Ty, TCK)};
792 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
793 PtrAsInt ? PtrAsInt : Ptr);
808 if (!IsGuaranteedNonNull) {
810 IsNonNull =
Builder.CreateIsNotNull(Ptr);
814 Builder.CreateCondBr(IsNonNull, VptrNotNull, Done);
824 llvm::raw_svector_ostream Out(MangledName);
831 llvm::hash_code TypeHash =
hash_value(Out.str());
834 llvm::Value *Low = llvm::ConstantInt::get(
Int64Ty, TypeHash);
843 const int CacheSize = 128;
844 llvm::Type *HashTable = llvm::ArrayType::get(
IntPtrTy, CacheSize);
846 "__ubsan_vptr_type_cache");
847 llvm::Value *Slot =
Builder.CreateAnd(Hash,
850 llvm::Value *Indices[] = {
Builder.getInt32(0), Slot };
859 llvm::Value *EqualHash =
Builder.CreateICmpEQ(CacheVal, Hash);
860 llvm::Constant *StaticData[] = {
864 llvm::ConstantInt::get(
Int8Ty, TCK)
866 llvm::Value *DynamicData[] = { Ptr, Hash };
867 EmitCheck(std::make_pair(EqualHash, SanitizerKind::Vptr),
868 SanitizerHandler::DynamicTypeCacheMiss, StaticData,
882 uint64_t EltSize =
C.getTypeSizeInChars(EltTy).getQuantity();
890 auto *ParamDecl = dyn_cast<ParmVarDecl>(ArrayDeclRef->getDecl());
894 auto *POSAttr = ParamDecl->getAttr<PassObjectSizeAttr>();
899 int POSType = POSAttr->getType();
900 if (POSType != 0 && POSType != 1)
904 auto PassedSizeIt = SizeArguments.find(ParamDecl);
905 if (PassedSizeIt == SizeArguments.end())
909 assert(LocalDeclMap.count(PassedSizeDecl) &&
"Passed size not loadable");
910 Address AddrOfSize = LocalDeclMap.find(PassedSizeDecl)->second;
913 llvm::Value *SizeOfElement =
914 llvm::ConstantInt::get(SizeInBytes->getType(), EltSize);
915 return Builder.CreateUDiv(SizeInBytes, SizeOfElement);
924 StrictFlexArraysLevel) {
927 IndexedType =
Base->getType();
928 return CGF.
Builder.getInt32(VT->getNumElements());
933 if (
const auto *CE = dyn_cast<CastExpr>(
Base)) {
934 if (CE->getCastKind() == CK_ArrayToPointerDecay &&
935 !CE->getSubExpr()->isFlexibleArrayMemberLike(CGF.
getContext(),
936 StrictFlexArraysLevel)) {
937 CodeGenFunction::SanitizerScope SanScope(&CGF);
939 IndexedType = CE->getSubExpr()->getType();
941 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
942 return CGF.
Builder.getInt(CAT->getSize());
944 if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
950 CodeGenFunction::SanitizerScope SanScope(&CGF);
952 QualType EltTy{
Base->getType()->getPointeeOrArrayElementType(), 0};
954 IndexedType =
Base->getType();
979class StructAccessBase
983 bool IsExpectedRecordDecl(
const Expr *E)
const {
991 StructAccessBase(
const RecordDecl *ExpectedRD) : ExpectedRD(ExpectedRD) {}
1014 const Expr *VisitStmt(
const Stmt *S) {
return nullptr; }
1030 return IsExpectedRecordDecl(E) ? E :
nullptr;
1033 if (IsExpectedRecordDecl(E) && E->
isArrow())
1036 return !Res && IsExpectedRecordDecl(E) ? E : Res;
1039 return IsExpectedRecordDecl(E) ? E :
nullptr;
1042 return IsExpectedRecordDecl(E) ? E :
nullptr;
1046 if (IsExpectedRecordDecl(E))
1072 int64_t FieldNo = -1;
1074 if (
const auto *Field = dyn_cast<FieldDecl>(D)) {
1077 Indices.emplace_back(std::make_pair(RD, CGF.
Builder.getInt32(FieldNo)));
1082 if (
const auto *
Record = dyn_cast<RecordDecl>(D)) {
1087 Indices.emplace_back(std::make_pair(RD, CGF.
Builder.getInt32(FieldNo)));
1109 const Expr *StructBase = StructAccessBase(RD).Visit(
Base);
1113 llvm::Value *Res =
nullptr;
1114 if (
const auto *DRE = dyn_cast<DeclRefExpr>(StructBase)) {
1118 }
else if (
const MemberExpr *ME = dyn_cast<MemberExpr>(StructBase)) {
1136 for (
auto I = Indices.rbegin(), E = Indices.rend(); I != E; ++I)
1139 {Zero, I->second},
"..counted_by.gep");
1153 const auto *CountDRE = cast<DeclRefExpr>(CAT->getCountExpr());
1154 const auto *CountDecl = CountDRE->getDecl();
1155 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(CountDecl))
1156 CountDecl = IFD->getAnonField();
1158 return dyn_cast<FieldDecl>(CountDecl);
1162 llvm::Value *Index,
QualType IndexType,
1164 assert(
SanOpts.
has(SanitizerKind::ArrayBounds) &&
1165 "should not be called unless adding bounds checks");
1169 llvm::Value *Bound =
1178 QualType IndexedType,
bool Accessed) {
1182 SanitizerScope SanScope(
this);
1185 llvm::Value *IndexVal =
Builder.CreateIntCast(Index,
SizeTy, IndexSigned);
1186 llvm::Value *BoundVal =
Builder.CreateIntCast(Bound,
SizeTy,
false);
1188 llvm::Constant *StaticData[] = {
1193 llvm::Value *Check = Accessed ?
Builder.CreateICmpULT(IndexVal, BoundVal)
1194 :
Builder.CreateICmpULE(IndexVal, BoundVal);
1195 EmitCheck(std::make_pair(Check, SanitizerKind::ArrayBounds),
1196 SanitizerHandler::OutOfBounds, StaticData, Index);
1201 bool isInc,
bool isPre) {
1204 llvm::Value *NextVal;
1205 if (isa<llvm::IntegerType>(InVal.first->getType())) {
1206 uint64_t AmountVal = isInc ? 1 : -1;
1207 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
1210 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1213 llvm::APFloat FVal(
getContext().getFloatTypeSemantics(ElemTy), 1);
1219 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1232 return isPre ? IncVal : InVal;
1242 DI->EmitExplicitCastType(E->
getType());
1259 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
1260 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(CE))
1263 switch (CE->getCastKind()) {
1267 case CK_AddressSpaceConversion:
1268 if (
auto PtrTy = CE->getSubExpr()->getType()->getAs<
PointerType>()) {
1269 if (PtrTy->getPointeeType()->isVoidType())
1275 CE->getSubExpr(), &InnerBaseInfo, &InnerTBAAInfo, IsKnownNonNull);
1276 if (BaseInfo) *BaseInfo = InnerBaseInfo;
1277 if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
1279 if (isa<ExplicitCastExpr>(CE)) {
1283 E->
getType(), &TargetTypeBaseInfo, &TargetTypeTBAAInfo);
1296 if (CGF.
SanOpts.
has(SanitizerKind::CFIUnrelatedCast) &&
1297 CE->getCastKind() == CK_BitCast) {
1305 llvm::Type *ElemTy =
1308 if (CE->getCastKind() == CK_AddressSpaceConversion)
1316 case CK_ArrayToPointerDecay:
1320 case CK_UncheckedDerivedToBase:
1321 case CK_DerivedToBase: {
1328 CE->getSubExpr(), BaseInfo,
nullptr,
1330 CE->getCastKind() == CK_UncheckedDerivedToBase));
1331 auto Derived = CE->getSubExpr()->
getType()->getPointeeCXXRecordDecl();
1333 Addr, Derived, CE->path_begin(), CE->path_end(),
1346 if (UO->getOpcode() == UO_AddrOf) {
1355 if (
auto *
Call = dyn_cast<CallExpr>(E)) {
1356 switch (
Call->getBuiltinCallee()) {
1359 case Builtin::BIaddressof:
1360 case Builtin::BI__addressof:
1361 case Builtin::BI__builtin_addressof: {
1375 true, BaseInfo, TBAAInfo, IsKnownNonNull);
1394 return Builder.CreateICmpNE(
V, llvm::Constant::getNullValue(
V->getType()));
1405 llvm::Value *
U = llvm::UndefValue::get(EltTy);
1420 llvm_unreachable(
"bad evaluation kind");
1440 while (!isa<CXXThisExpr>(
Base)) {
1442 if (isa<CXXDynamicCastExpr>(
Base))
1445 if (
const auto *CE = dyn_cast<CastExpr>(
Base)) {
1446 Base = CE->getSubExpr();
1447 }
else if (
const auto *PE = dyn_cast<ParenExpr>(
Base)) {
1448 Base = PE->getSubExpr();
1449 }
else if (
const auto *UO = dyn_cast<UnaryOperator>(
Base)) {
1450 if (UO->getOpcode() == UO_Extension)
1451 Base = UO->getSubExpr();
1463 if (
SanOpts.
has(SanitizerKind::ArrayBounds) && isa<ArraySubscriptExpr>(E))
1469 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
1472 SkippedChecks.
set(SanitizerKind::Alignment,
true);
1473 if (IsBaseCXXThis || isa<DeclRefExpr>(ME->getBase()))
1474 SkippedChecks.
set(SanitizerKind::Null,
true);
1498 LValue LV = EmitLValueHelper(E, IsKnownNonNull);
1507 if (isa<OpaqueValueExpr>(SE))
1509 return cast<CallExpr>(SE)->getCallReturnType(Ctx)->
getPointeeType();
1512LValue CodeGenFunction::EmitLValueHelper(
const Expr *E,
1518 case Expr::ObjCPropertyRefExprClass:
1519 llvm_unreachable(
"cannot emit a property reference directly");
1521 case Expr::ObjCSelectorExprClass:
1523 case Expr::ObjCIsaExprClass:
1525 case Expr::BinaryOperatorClass:
1527 case Expr::CompoundAssignOperatorClass: {
1530 Ty = AT->getValueType();
1535 case Expr::CallExprClass:
1536 case Expr::CXXMemberCallExprClass:
1537 case Expr::CXXOperatorCallExprClass:
1538 case Expr::UserDefinedLiteralClass:
1540 case Expr::CXXRewrittenBinaryOperatorClass:
1541 return EmitLValue(cast<CXXRewrittenBinaryOperator>(E)->getSemanticForm(),
1543 case Expr::VAArgExprClass:
1545 case Expr::DeclRefExprClass:
1547 case Expr::ConstantExprClass: {
1553 return EmitLValue(cast<ConstantExpr>(E)->getSubExpr(), IsKnownNonNull);
1555 case Expr::ParenExprClass:
1556 return EmitLValue(cast<ParenExpr>(E)->getSubExpr(), IsKnownNonNull);
1557 case Expr::GenericSelectionExprClass:
1558 return EmitLValue(cast<GenericSelectionExpr>(E)->getResultExpr(),
1560 case Expr::PredefinedExprClass:
1562 case Expr::StringLiteralClass:
1564 case Expr::ObjCEncodeExprClass:
1566 case Expr::PseudoObjectExprClass:
1568 case Expr::InitListExprClass:
1570 case Expr::CXXTemporaryObjectExprClass:
1571 case Expr::CXXConstructExprClass:
1573 case Expr::CXXBindTemporaryExprClass:
1575 case Expr::CXXUuidofExprClass:
1577 case Expr::LambdaExprClass:
1580 case Expr::ExprWithCleanupsClass: {
1581 const auto *cleanups = cast<ExprWithCleanups>(E);
1582 RunCleanupsScope
Scope(*
this);
1589 Scope.ForceCleanup({&
V});
1599 case Expr::CXXDefaultArgExprClass: {
1600 auto *DAE = cast<CXXDefaultArgExpr>(E);
1601 CXXDefaultArgExprScope
Scope(*
this, DAE);
1602 return EmitLValue(DAE->getExpr(), IsKnownNonNull);
1604 case Expr::CXXDefaultInitExprClass: {
1605 auto *DIE = cast<CXXDefaultInitExpr>(E);
1606 CXXDefaultInitExprScope
Scope(*
this, DIE);
1607 return EmitLValue(DIE->getExpr(), IsKnownNonNull);
1609 case Expr::CXXTypeidExprClass:
1612 case Expr::ObjCMessageExprClass:
1614 case Expr::ObjCIvarRefExprClass:
1616 case Expr::StmtExprClass:
1618 case Expr::UnaryOperatorClass:
1620 case Expr::ArraySubscriptExprClass:
1622 case Expr::MatrixSubscriptExprClass:
1624 case Expr::ArraySectionExprClass:
1626 case Expr::ExtVectorElementExprClass:
1628 case Expr::CXXThisExprClass:
1630 case Expr::MemberExprClass:
1632 case Expr::CompoundLiteralExprClass:
1634 case Expr::ConditionalOperatorClass:
1636 case Expr::BinaryConditionalOperatorClass:
1638 case Expr::ChooseExprClass:
1639 return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr(), IsKnownNonNull);
1640 case Expr::OpaqueValueExprClass:
1642 case Expr::SubstNonTypeTemplateParmExprClass:
1643 return EmitLValue(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(),
1645 case Expr::ImplicitCastExprClass:
1646 case Expr::CStyleCastExprClass:
1647 case Expr::CXXFunctionalCastExprClass:
1648 case Expr::CXXStaticCastExprClass:
1649 case Expr::CXXDynamicCastExprClass:
1650 case Expr::CXXReinterpretCastExprClass:
1651 case Expr::CXXConstCastExprClass:
1652 case Expr::CXXAddrspaceCastExprClass:
1653 case Expr::ObjCBridgedCastExprClass:
1656 case Expr::MaterializeTemporaryExprClass:
1659 case Expr::CoawaitExprClass:
1661 case Expr::CoyieldExprClass:
1663 case Expr::PackIndexingExprClass:
1664 return EmitLValue(cast<PackIndexingExpr>(E)->getSelectedExpr());
1671 assert(
type.isCanonical());
1672 assert(!
type->isReferenceType());
1680 if (
const auto *RT = dyn_cast<RecordType>(
type))
1681 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1682 if (RD->hasMutableFields() || !RD->isTrivial())
1703 if (
const auto *ref = dyn_cast<ReferenceType>(
type)) {
1719CodeGenFunction::ConstantEmission
1725 if (isa<ParmVarDecl>(value)) {
1727 }
else if (
auto *var = dyn_cast<VarDecl>(value)) {
1729 }
else if (isa<EnumConstantDecl>(value)) {
1734 if (CEK ==
CEK_None)
return ConstantEmission();
1737 bool resultIsReference;
1743 resultIsReference =
false;
1744 resultType = refExpr->
getType();
1749 resultIsReference =
true;
1750 resultType = value->
getType();
1754 return ConstantEmission();
1759 return ConstantEmission();
1770 auto *MD = dyn_cast_or_null<CXXMethodDecl>(
CurCodeDecl);
1771 if (MD && MD->getParent()->isLambda() &&
1772 MD->getOverloadedOperator() == OO_Call) {
1775 if (
const VarDecl *VD = dyn_cast<const VarDecl>(D)) {
1776 if (!VD->hasAttr<CUDADeviceAttr>()) {
1777 return ConstantEmission();
1786 result.
Val, resultType);
1790 if (isa<VarDecl>(value)) {
1791 if (!
getContext().DeclMustBeEmitted(cast<VarDecl>(value)))
1794 assert(isa<EnumConstantDecl>(value));
1799 if (resultIsReference)
1817CodeGenFunction::ConstantEmission
1821 return ConstantEmission();
1825 const CodeGenFunction::ConstantEmission &Constant,
Expr *E) {
1826 assert(Constant &&
"not a constant");
1827 if (Constant.isReference())
1831 return Constant.getValue();
1846 return ET->getDecl()->getIntegerType()->isBooleanType();
1855 llvm::APInt &
Min, llvm::APInt &End,
1856 bool StrictEnums,
bool IsBool) {
1858 bool IsRegularCPlusPlusEnum = CGF.
getLangOpts().CPlusPlus && StrictEnums &&
1860 if (!IsBool && !IsRegularCPlusPlusEnum)
1873llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(
QualType Ty) {
1874 llvm::APInt
Min, End;
1880 return MDHelper.createRange(
Min, End);
1885 bool HasBoolCheck =
SanOpts.
has(SanitizerKind::Bool);
1886 bool HasEnumCheck =
SanOpts.
has(SanitizerKind::Enum);
1887 if (!HasBoolCheck && !HasEnumCheck)
1892 bool NeedsBoolCheck = HasBoolCheck && IsBool;
1893 bool NeedsEnumCheck = HasEnumCheck && Ty->
getAs<
EnumType>();
1894 if (!NeedsBoolCheck && !NeedsEnumCheck)
1901 cast<llvm::IntegerType>(
Value->
getType())->getBitWidth() == 1)
1904 llvm::APInt
Min, End;
1909 SanitizerScope SanScope(
this);
1913 Check =
Builder.CreateICmpULE(
Value, llvm::ConstantInt::get(Ctx, End));
1915 llvm::Value *Upper =
1916 Builder.CreateICmpSLE(
Value, llvm::ConstantInt::get(Ctx, End));
1917 llvm::Value *Lower =
1919 Check =
Builder.CreateAnd(Upper, Lower);
1924 NeedsEnumCheck ? SanitizerKind::Enum : SanitizerKind::Bool;
1925 EmitCheck(std::make_pair(Check, Kind), SanitizerHandler::LoadInvalidValue,
1935 bool isNontemporal) {
1936 if (
auto *GV = dyn_cast<llvm::GlobalValue>(Addr.
getBasePointer()))
1937 if (GV->isThreadLocal())
1943 if (ClangVecTy->isExtVectorBoolType()) {
1945 unsigned ValNumElems =
1946 cast<llvm::FixedVectorType>(ValTy)->getNumElements();
1949 const auto *RawIntTy = RawIntV->getType();
1950 assert(RawIntTy->isIntegerTy() &&
"compressed iN storage for bitvectors");
1952 auto *PaddedVecTy = llvm::FixedVectorType::get(
1953 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());
1954 llvm::Value *
V =
Builder.CreateBitCast(RawIntV, PaddedVecTy);
1963 const auto *VTy = cast<llvm::FixedVectorType>(EltTy);
1967 llvm::VectorType *vec4Ty =
1968 llvm::FixedVectorType::get(VTy->getElementType(), 4);
1987 if (isNontemporal) {
1988 llvm::MDNode *
Node = llvm::MDNode::get(
1989 Load->getContext(), llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1990 Load->setMetadata(llvm::LLVMContext::MD_nontemporal,
Node);
1999 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) {
2000 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
2001 Load->setMetadata(llvm::LLVMContext::MD_noundef,
2016 "wrong value rep of bool");
2026 "wrong value rep of bool");
2032 auto *PaddedVecTy = llvm::FixedVectorType::get(
2033 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());
2037 unsigned ValNumElems = cast<llvm::FixedVectorType>(ValTy)->getNumElements();
2048 bool IsVector =
true) {
2049 auto *ArrayTy = dyn_cast<llvm::ArrayType>(Addr.
getElementType());
2050 if (ArrayTy && IsVector) {
2051 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),
2052 ArrayTy->getNumElements());
2056 auto *VectorTy = dyn_cast<llvm::VectorType>(Addr.
getElementType());
2057 if (VectorTy && !IsVector) {
2058 auto *ArrayTy = llvm::ArrayType::get(
2059 VectorTy->getElementType(),
2060 cast<llvm::FixedVectorType>(VectorTy)->getNumElements());
2074 value->getType()->isVectorTy());
2084 bool isInit,
bool isNontemporal) {
2085 if (
auto *GV = dyn_cast<llvm::GlobalValue>(Addr.
getBasePointer()))
2086 if (GV->isThreadLocal())
2092 auto *VecTy = dyn_cast<llvm::FixedVectorType>(SrcTy);
2093 if (VecTy && ClangVecTy->isExtVectorBoolType()) {
2096 unsigned MemNumElems = MemIntTy->getPrimitiveSizeInBits();
2103 if (VecTy && cast<llvm::FixedVectorType>(VecTy)->getNumElements() == 3) {
2107 SrcTy = llvm::FixedVectorType::get(VecTy->getElementType(), 4);
2126 if (isNontemporal) {
2127 llvm::MDNode *
Node =
2128 llvm::MDNode::get(
Store->getContext(),
2129 llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
2130 Store->setMetadata(llvm::LLVMContext::MD_nontemporal,
Node);
2211 llvm::MatrixBuilder MB(
Builder);
2212 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
2214 llvm::LoadInst *
Load =
2219 assert(LV.
isBitField() &&
"Unknown LValue type!");
2237 const unsigned StorageSize =
2240 assert(
static_cast<unsigned>(Offset + Info.
Size) <= StorageSize);
2241 unsigned HighBits = StorageSize - Offset - Info.
Size;
2243 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
2244 if (Offset + HighBits)
2245 Val =
Builder.CreateAShr(Val, Offset + HighBits,
"bf.ashr");
2248 Val =
Builder.CreateLShr(Val, Offset,
"bf.lshr");
2249 if (
static_cast<unsigned>(Offset) + Info.
Size < StorageSize)
2251 Val, llvm::APInt::getLowBitsSet(StorageSize, Info.
Size),
"bf.clear");
2267 llvm::Type *DstTy = llvm::FixedVectorType::get(Vec->getType(), 1);
2269 Vec =
Builder.CreateInsertElement(DstTy, Vec, Zero,
"cast.splat");
2279 llvm::Value *Elt = llvm::ConstantInt::get(
SizeTy, InIdx);
2287 for (
unsigned i = 0; i != NumResultElts; ++i)
2290 Vec =
Builder.CreateShuffleVector(Vec, Mask);
2309 return VectorBasePtrPlusIx;
2315 "Bad type for register variable");
2316 llvm::MDNode *RegName = cast<llvm::MDNode>(
2317 cast<llvm::MetadataAsValue>(LV.
getGlobalReg())->getMetadata());
2321 llvm::Type *Ty = OrigTy;
2322 if (OrigTy->isPointerTy())
2324 llvm::Type *Types[] = { Ty };
2326 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::read_register, Types);
2328 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
2329 if (OrigTy->isPointerTy())
2344 auto *IRStoreTy = dyn_cast<llvm::IntegerType>(Vec->getType());
2346 auto *IRVecTy = llvm::FixedVectorType::get(
2347 Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());
2348 Vec =
Builder.CreateBitCast(Vec, IRVecTy);
2355 Vec =
Builder.CreateBitCast(Vec, IRStoreTy);
2374 llvm::MatrixBuilder MB(
Builder);
2375 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
2385 assert(Dst.
isBitField() &&
"Unknown LValue type");
2393 llvm_unreachable(
"present but none");
2441 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
2443 ResultType,
"sub.ptr.lhs.cast");
2444 llvm::Value *BytesBetween =
Builder.CreateSub(LHS, RHS,
"ivar.offset");
2455 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
2471 llvm::Value *MaskedVal = SrcVal;
2473 const bool UseVolatile =
2476 const unsigned StorageSize =
2481 if (StorageSize != Info.
Size) {
2482 assert(StorageSize > Info.
Size &&
"Invalid bitfield size.");
2489 SrcVal, llvm::APInt::getLowBitsSet(StorageSize, Info.
Size),
2493 SrcVal =
Builder.CreateShl(SrcVal, Offset,
"bf.shl");
2497 Val, ~llvm::APInt::getBitsSet(StorageSize, Offset, Offset + Info.
Size),
2501 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
2503 assert(Offset == 0);
2519 llvm::Value *ResultVal = MaskedVal;
2523 assert(Info.
Size <= StorageSize);
2524 unsigned HighBits = StorageSize - Info.
Size;
2526 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
2527 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
2545 "this should only occur for non-vector l-values");
2558 unsigned NumSrcElts = VTy->getNumElements();
2559 unsigned NumDstElts =
2560 cast<llvm::FixedVectorType>(Vec->getType())->getNumElements();
2561 if (NumDstElts == NumSrcElts) {
2566 for (
unsigned i = 0; i != NumSrcElts; ++i)
2569 Vec =
Builder.CreateShuffleVector(SrcVal, Mask);
2570 }
else if (NumDstElts > NumSrcElts) {
2576 for (
unsigned i = 0; i != NumSrcElts; ++i)
2577 ExtMask.push_back(i);
2578 ExtMask.resize(NumDstElts, -1);
2579 llvm::Value *ExtSrcVal =
Builder.CreateShuffleVector(SrcVal, ExtMask);
2582 for (
unsigned i = 0; i != NumDstElts; ++i)
2592 for (
unsigned i = 0; i != NumSrcElts; ++i)
2594 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, Mask);
2597 llvm_unreachable(
"unexpected shorten vector length");
2603 llvm::Value *Elt = llvm::ConstantInt::get(
SizeTy, InIdx);
2604 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
2614 "Bad type for register variable");
2615 llvm::MDNode *RegName = cast<llvm::MDNode>(
2616 cast<llvm::MetadataAsValue>(Dst.
getGlobalReg())->getMetadata());
2617 assert(RegName &&
"Register LValue is not metadata");
2621 llvm::Type *Ty = OrigTy;
2622 if (OrigTy->isPointerTy())
2624 llvm::Type *Types[] = { Ty };
2626 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
2628 if (OrigTy->isPointerTy())
2631 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName),
Value});
2639 bool IsMemberAccess=
false) {
2643 if (isa<ObjCIvarRefExpr>(E)) {
2656 auto *Exp = cast<ObjCIvarRefExpr>(
const_cast<Expr *
>(E));
2662 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
2663 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
2664 if (VD->hasGlobalStorage()) {
2673 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
2678 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
2692 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
2697 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
2702 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
2707 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
2712 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
2725 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
2739 CGF, VD, Addr, Loc);
2750 std::optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res =
2751 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
2755 if (!Res || ((*Res == OMPDeclareTargetDeclAttr::MT_To ||
2756 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&
2759 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||
2760 ((*Res == OMPDeclareTargetDeclAttr::MT_To ||
2761 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&
2763 "Expected link clause OR to clause with unified memory enabled.");
2773 llvm::LoadInst *
Load =
2778 PointeeBaseInfo, PointeeTBAAInfo);
2787 PointeeBaseInfo, PointeeTBAAInfo);
2797 BaseInfo, TBAAInfo);
2827 V = CGF.
Builder.CreateThreadLocalAddress(
V);
2831 Address Addr(
V, RealVarTy, Alignment);
2835 VD->
hasAttr<OMPThreadPrivateDeclAttr>()) {
2850 if (FD->
hasAttr<WeakRefAttr>()) {
2869 llvm::Value *ThisValue) {
2882 AsmLabelAttr *
Asm = VD->
getAttr<AsmLabelAttr>();
2883 assert(
Asm->getLabel().size() < 64-Name.size() &&
2884 "Register name too big");
2885 Name.append(
Asm->getLabel());
2886 llvm::NamedMDNode *M =
2887 CGM.
getModule().getOrInsertNamedMetadata(Name);
2888 if (M->getNumOperands() == 0) {
2891 llvm::Metadata *Ops[] = {Str};
2898 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0));
2941 case llvm::GlobalValue::ExternalLinkage:
2942 case llvm::GlobalValue::LinkOnceODRLinkage:
2943 case llvm::GlobalValue::WeakODRLinkage:
2944 case llvm::GlobalValue::InternalLinkage:
2945 case llvm::GlobalValue::PrivateLinkage:
2957 "should not emit an unevaluated operand");
2959 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2962 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
2970 (VD->getType()->isReferenceType() ||
2972 VD->getAnyInitializer(VD);
2974 E->
getLocation(), *VD->evaluateValue(), VD->getType());
2975 assert(Val &&
"failed to emit constant expression");
2978 if (!VD->getType()->isReferenceType()) {
2983 auto *PTy = llvm::PointerType::get(
2984 VarTy,
getTypes().getTargetAddressSpace(VD->getType()));
3002 VD = VD->getCanonicalDecl();
3006 auto I = LocalDeclMap.find(VD);
3007 if (I != LocalDeclMap.end()) {
3009 if (VD->getType()->isReferenceType())
3050 "Should not use decl without marking it used!");
3052 if (ND->
hasAttr<WeakRefAttr>()) {
3053 const auto *VD = cast<ValueDecl>(ND);
3058 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
3060 if (VD->hasLinkage() || VD->isStaticDataMember())
3066 auto iter = LocalDeclMap.find(VD);
3067 if (iter != LocalDeclMap.end()) {
3068 addr = iter->second;
3072 }
else if (VD->isStaticLocal()) {
3080 llvm_unreachable(
"DeclRefExpr for Decl not entered in LocalDeclMap?");
3091 VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
3098 bool isBlockByref = VD->isEscapingByref();
3108 bool isLocalStorage = VD->hasLocalStorage();
3110 bool NonGCable = isLocalStorage &&
3118 bool isImpreciseLifetime =
3119 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
3120 if (isImpreciseLifetime)
3126 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
3130 if (
getContext().getTargetInfo().allowDebugInfoForExternalRef()) {
3133 cast<llvm::Function>(LV.
getPointer(*this)->stripPointerCasts());
3134 if (!Fn->getSubprogram())
3145 if (
const auto *BD = dyn_cast<BindingDecl>(ND)) {
3155 if (
const auto *GD = dyn_cast<MSGuidDecl>(ND))
3159 if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
3163 if (AS !=
T.getAddressSpace()) {
3165 auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS);
3167 CGM, ATPO.getPointer(), AS,
T.getAddressSpace(), PtrTy);
3168 ATPO =
ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
3174 llvm_unreachable(
"Unhandled DeclRefExpr");
3184 default: llvm_unreachable(
"Unknown unary operator lvalue!");
3187 assert(!
T.isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
3209 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
3233 bool isInc = E->
getOpcode() == UO_PreInc;
3256 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
3257 StringRef FnName =
CurFn->getName();
3258 if (FnName.starts_with(
"\01"))
3259 FnName = FnName.substr(1);
3260 StringRef NameItems[] = {
3262 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
3263 if (
auto *BD = dyn_cast_or_null<BlockDecl>(
CurCodeDecl)) {
3264 std::string Name = std::string(SL->getString());
3265 if (!Name.empty()) {
3266 unsigned Discriminator =
3269 Name +=
"_" + Twine(Discriminator + 1).str();
3296 uint16_t TypeKind = -1;
3313 StringRef(), std::nullopt, Buffer, std::nullopt);
3315 llvm::Constant *Components[] = {
3319 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
3321 auto *GV =
new llvm::GlobalVariable(
3323 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
3324 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3336 if (
V->getType() == TargetTy)
3341 if (
V->getType()->isFloatingPointTy()) {
3342 unsigned Bits =
V->getType()->getPrimitiveSizeInBits().getFixedValue();
3343 if (Bits <= TargetTy->getIntegerBitWidth())
3349 if (
V->getType()->isIntegerTy() &&
3350 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
3351 return Builder.CreateZExt(
V, TargetTy);
3354 if (!
V->getType()->isPointerTy()) {
3359 return Builder.CreatePtrToInt(
V, TargetTy);
3379 int PathComponentsToStrip =
3381 if (PathComponentsToStrip < 0) {
3382 assert(PathComponentsToStrip !=
INT_MIN);
3383 int PathComponentsToKeep = -PathComponentsToStrip;
3384 auto I = llvm::sys::path::rbegin(FilenameString);
3385 auto E = llvm::sys::path::rend(FilenameString);
3386 while (I != E && --PathComponentsToKeep)
3389 FilenameString = FilenameString.substr(I - E);
3390 }
else if (PathComponentsToStrip > 0) {
3391 auto I = llvm::sys::path::begin(FilenameString);
3392 auto E = llvm::sys::path::end(FilenameString);
3393 while (I != E && PathComponentsToStrip--)
3398 FilenameString.substr(I - llvm::sys::path::begin(FilenameString));
3400 FilenameString = llvm::sys::path::filename(FilenameString);
3406 cast<llvm::GlobalVariable>(
3407 FilenameGV.getPointer()->stripPointerCasts()));
3408 Filename = FilenameGV.getPointer();
3419 return llvm::ConstantStruct::getAnon(
Data);
3424enum class CheckRecoverableKind {
3436 assert(Kind.countPopulation() == 1);
3437 if (Kind == SanitizerKind::Vptr)
3438 return CheckRecoverableKind::AlwaysRecoverable;
3439 else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
3440 return CheckRecoverableKind::Unrecoverable;
3442 return CheckRecoverableKind::Recoverable;
3446struct SanitizerHandlerInfo {
3447 char const *
const Name;
3453#define SANITIZER_CHECK(Enum, Name, Version) {#Name, Version},
3455#undef SANITIZER_CHECK
3459 llvm::FunctionType *FnType,
3462 CheckRecoverableKind RecoverKind,
bool IsFatal,
3463 llvm::BasicBlock *ContBB) {
3464 assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
3465 std::optional<ApplyDebugLocation> DL;
3466 if (!CGF.
Builder.getCurrentDebugLocation()) {
3470 bool NeedsAbortSuffix =
3471 IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable;
3474 const StringRef CheckName = CheckInfo.Name;
3475 std::string FnName =
"__ubsan_handle_" + CheckName.str();
3476 if (CheckInfo.Version && !MinimalRuntime)
3477 FnName +=
"_v" + llvm::utostr(CheckInfo.Version);
3479 FnName +=
"_minimal";
3480 if (NeedsAbortSuffix)
3483 !IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;
3487 B.addAttribute(llvm::Attribute::NoReturn)
3488 .addAttribute(llvm::Attribute::NoUnwind);
3490 B.addUWTableAttr(llvm::UWTableKind::Default);
3495 llvm::AttributeList::FunctionIndex, B),
3499 HandlerCall->setDoesNotReturn();
3500 CGF.
Builder.CreateUnreachable();
3507 ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
3511 assert(Checked.size() > 0);
3512 assert(CheckHandler >= 0 &&
3516 llvm::Value *FatalCond =
nullptr;
3517 llvm::Value *RecoverableCond =
nullptr;
3518 llvm::Value *TrapCond =
nullptr;
3519 for (
int i = 0, n = Checked.size(); i < n; ++i) {
3520 llvm::Value *Check = Checked[i].first;
3522 llvm::Value *&Cond =
3528 Cond = Cond ?
Builder.CreateAnd(Cond, Check) : Check;
3532 llvm::Value *Allow =
3534 llvm::ConstantInt::get(
CGM.
Int8Ty, CheckHandler));
3536 for (llvm::Value **Cond : {&FatalCond, &RecoverableCond, &TrapCond}) {
3544 if (!FatalCond && !RecoverableCond)
3547 llvm::Value *JointCond;
3548 if (FatalCond && RecoverableCond)
3549 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
3551 JointCond = FatalCond ? FatalCond : RecoverableCond;
3557 for (
int i = 1, n = Checked.size(); i < n; ++i) {
3559 "All recoverable kinds in a single check must be same!");
3566 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
3570 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3571 Branch->setMetadata(llvm::LLVMContext::MD_prof,
Node);
3580 Args.reserve(DynamicArgs.size() + 1);
3581 ArgTypes.reserve(DynamicArgs.size() + 1);
3584 if (!StaticArgs.empty()) {
3585 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3586 auto *InfoPtr =
new llvm::GlobalVariable(
3588 llvm::GlobalVariable::PrivateLinkage, Info,
"",
nullptr,
3589 llvm::GlobalVariable::NotThreadLocal,
3591 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3593 Args.push_back(InfoPtr);
3594 ArgTypes.push_back(Args.back()->getType());
3597 for (
size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {
3603 llvm::FunctionType *FnType =
3604 llvm::FunctionType::get(
CGM.
VoidTy, ArgTypes,
false);
3606 if (!FatalCond || !RecoverableCond) {
3610 (FatalCond !=
nullptr), Cont);
3614 llvm::BasicBlock *NonFatalHandlerBB =
3617 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
3630 SanitizerMask Kind, llvm::Value *Cond, llvm::ConstantInt *TypeId,
3635 llvm::BranchInst *BI =
Builder.CreateCondBr(Cond, Cont, CheckBB);
3638 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3639 BI->setMetadata(llvm::LLVMContext::MD_prof,
Node);
3645 llvm::CallInst *CheckCall;
3646 llvm::FunctionCallee SlowPathFn;
3648 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3650 new llvm::GlobalVariable(
CGM.
getModule(), Info->getType(),
false,
3651 llvm::GlobalVariable::PrivateLinkage, Info);
3652 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3656 "__cfi_slowpath_diag",
3659 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr, InfoPtr});
3664 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
3668 cast<llvm::GlobalValue>(SlowPathFn.getCallee()->stripPointerCasts()));
3669 CheckCall->setDoesNotThrow();
3679 QualType QInt64Ty =
C.getIntTypeForBitwidth(64,
false);
3686 FnArgs.push_back(&ArgCallsiteTypeId);
3687 FnArgs.push_back(&ArgAddr);
3688 FnArgs.push_back(&ArgCFICheckFailData);
3692 llvm::Function *F = llvm::Function::Create(
3694 llvm::GlobalValue::WeakAnyLinkage,
"__cfi_check", M);
3697 F->setAlignment(llvm::Align(4096));
3700 llvm::LLVMContext &Ctx = M->getContext();
3701 llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx,
"entry", F);
3704 llvm::CallInst::Create(M->getFunction(
"__cfi_check_fail"), Args,
"", BB);
3705 llvm::ReturnInst::Create(Ctx,
nullptr, BB);
3716 SanitizerScope SanScope(
this);
3722 Args.push_back(&ArgData);
3723 Args.push_back(&ArgAddr);
3728 llvm::Function *F = llvm::Function::Create(
3730 llvm::GlobalValue::WeakODRLinkage,
"__cfi_check_fail", &
CGM.
getModule());
3734 F->setVisibility(llvm::GlobalValue::HiddenVisibility);
3752 llvm::Value *DataIsNotNullPtr =
3754 EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
3756 llvm::StructType *SourceLocationTy =
3758 llvm::StructType *CfiCheckFailDataTy =
3763 Builder.CreatePointerCast(
Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
3769 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
3772 llvm::Value *ValidVtable =
Builder.CreateZExt(
3774 {Addr, AllVtables}),
3777 const std::pair<int, SanitizerMask> CheckKinds[] = {
3785 for (
auto CheckKindMaskPair : CheckKinds) {
3786 int Kind = CheckKindMaskPair.first;
3789 Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(
Int8Ty, Kind));
3791 EmitCheck(std::make_pair(Cond, Mask), SanitizerHandler::CFICheckFail, {},
3792 {
Data, Addr, ValidVtable});
3804 if (
SanOpts.
has(SanitizerKind::Unreachable)) {
3805 SanitizerScope SanScope(
this);
3807 SanitizerKind::Unreachable),
3808 SanitizerHandler::BuiltinUnreachable,
3820 if ((
int)TrapBBs.size() <= CheckHandlerID)
3821 TrapBBs.resize(CheckHandlerID + 1);
3823 llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];
3828 auto Call = TrapBB->begin();
3829 assert(isa<llvm::CallInst>(
Call) &&
"Expected call in trap BB");
3831 Call->applyMergedLocation(
Call->getDebugLoc(),
3832 Builder.getCurrentDebugLocation());
3833 Builder.CreateCondBr(Checked, Cont, TrapBB);
3836 Builder.CreateCondBr(Checked, Cont, TrapBB);
3839 llvm::CallInst *TrapCall =
Builder.CreateCall(
3842 ? TrapBB->getParent()->size()
3846 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
3848 TrapCall->addFnAttr(A);
3850 TrapCall->setDoesNotReturn();
3851 TrapCall->setDoesNotThrow();
3859 llvm::CallInst *TrapCall =
3863 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
3865 TrapCall->addFnAttr(A);
3875 "Array to pointer decay must have array source type!");
3890 "Expected pointer to array");
3910 const auto *CE = dyn_cast<CastExpr>(E);
3911 if (!CE || CE->getCastKind() != CK_ArrayToPointerDecay)
3923 llvm::Type *elemType,
3929 const llvm::Twine &name =
"arrayidx") {
3941 llvm::Type *elementType,
bool inbounds,
3944 const llvm::Twine &name =
"arrayidx") {
3959 if (
auto constantIdx = dyn_cast<llvm::ConstantInt>(idx)) {
3960 CharUnits offset = constantIdx->getZExtValue() * eltSize;
3979 return D && D->
hasAttr<BPFPreserveStaticOffsetAttr>();
3986 if (PointeeType.
isNull())
3999 llvm::Function *Fn =
4019 if (
const auto *ME = dyn_cast<MemberExpr>(E))
4022 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
4023 const auto *VarDef = dyn_cast<VarDecl>(DRE->getDecl());
4027 const auto *PtrT = VarDef->getType()->getAs<
PointerType>();
4033 if (
const auto *RecT = dyn_cast<RecordType>(PointeeT))
4034 return RecT->getDecl()->
hasAttr<BPFPreserveAccessIndexAttr>();
4047 const llvm::Twine &name =
"arrayidx") {
4050 for (
auto *idx : indices.drop_back())
4051 assert(isa<llvm::ConstantInt>(idx) &&
4052 cast<llvm::ConstantInt>(idx)->isZero());
4069 llvm::Value *eltPtr;
4070 auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
4075 signedIndices, loc, eltAlign, name);
4079 unsigned idx = LastIndex->getZExtValue();
4080 llvm::DIType *DbgInfo =
nullptr;
4083 eltPtr = CGF.
Builder.CreatePreserveArrayAccessIndex(
4096 unsigned FieldNo = 0;
4099 if (
const auto *
Record = dyn_cast<RecordDecl>(D))
4105 if (
const auto *Field = dyn_cast<FieldDecl>(D))
4111 if (isa<FieldDecl>(D))
4131 if (FD1OuterRec != FD2OuterRec)
4133 return std::optional<int64_t>();
4135 int64_t FD1Offset = 0;
4137 return std::optional<int64_t>();
4139 int64_t FD2Offset = 0;
4141 return std::optional<int64_t>();
4143 return std::make_optional<int64_t>(FD1Offset - FD2Offset);
4150 llvm::Value *IdxPre =
4152 bool SignedIndices =
false;
4153 auto EmitIdxAfterBase = [&, IdxPre](
bool Promote) -> llvm::Value * {
4156 assert(E->
getRHS() == E->
getIdx() &&
"index was neither LHS nor RHS");
4162 SignedIndices |= IdxSigned;
4168 if (Promote && Idx->getType() !=
IntPtrTy)
4178 !isa<ExtVectorElementExpr>(E->
getBase())) {
4181 auto *Idx = EmitIdxAfterBase(
false);
4182 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
4191 if (isa<ExtVectorElementExpr>(E->
getBase())) {
4193 auto *Idx = EmitIdxAfterBase(
true);
4212 auto *Idx = EmitIdxAfterBase(
true);
4222 Idx =
Builder.CreateMul(Idx, numElements);
4224 Idx =
Builder.CreateNSWMul(Idx, numElements);
4236 auto *Idx = EmitIdxAfterBase(
true);
4239 llvm::Value *InterfaceSizeVal =
4240 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.
getQuantity());
4242 llvm::Value *ScaledIdx =
Builder.CreateMul(Idx, InterfaceSizeVal);
4253 llvm::Value *EltPtr =
4255 ScaledIdx,
false, SignedIndices, E->
getExprLoc());
4256 Addr =
Address(EltPtr, OrigBaseElemTy, EltAlign);
4262 assert(Array->getType()->isArrayType() &&
4263 "Array to pointer decay must have array source type!");
4267 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
4271 auto *Idx = EmitIdxAfterBase(
true);
4273 if (
SanOpts.
has(SanitizerKind::ArrayBounds)) {
4284 if (
const auto *ME = dyn_cast<MemberExpr>(Array);
4290 if (std::optional<int64_t> Diff =
4299 llvm::Type *CountTy =
ConvertType(CountFD->getType());
4304 ".counted_by.load");
4308 Array->getType(), Accessed);
4317 *
this, ArrayLV.
getAddress(*
this), {CGM.getSize(CharUnits::Zero()), Idx},
4325 auto *Idx = EmitIdxAfterBase(
true);
4346 "incomplete matrix subscript expressions should be rejected during Sema");
4350 llvm::Value *NumRows =
Builder.getIntN(
4351 RowIdx->getType()->getScalarSizeInBits(),
4353 llvm::Value *FinalIdx =
4364 bool IsLowerBound) {
4366 if (
auto *ASE = dyn_cast<ArraySectionExpr>(
Base->IgnoreParenImpCasts())) {
4381 "Expected pointer to array");
4400 bool IsLowerBound) {
4403 "OpenACC Array section codegen not implemented");
4407 if (
auto *AT =
getContext().getAsArrayType(BaseTy))
4408 ResultExprTy = AT->getElementType();
4411 llvm::Value *Idx =
nullptr;
4419 LowerBound->getType()->hasSignedIntegerRepresentation());
4421 Idx = llvm::ConstantInt::getNullValue(
IntPtrTy);
4428 llvm::APSInt ConstLength;
4431 if (std::optional<llvm::APSInt> CL = Length->getIntegerConstantExpr(
C)) {
4438 if (std::optional<llvm::APSInt> LB =
4439 LowerBound->getIntegerConstantExpr(
C)) {
4441 LowerBound =
nullptr;
4446 else if (!LowerBound)
4449 if (Length || LowerBound) {
4450 auto *LowerBoundVal =
4454 LowerBound->getType()->hasSignedIntegerRepresentation())
4455 : llvm::ConstantInt::get(
IntPtrTy, ConstLowerBound);
4460 Length->getType()->hasSignedIntegerRepresentation())
4461 : llvm::ConstantInt::get(
IntPtrTy, ConstLength);
4462 Idx =
Builder.CreateAdd(LowerBoundVal, LengthVal,
"lb_add_len",
4465 if (Length && LowerBound) {
4467 Idx, llvm::ConstantInt::get(
IntPtrTy, 1),
"idx_sub_1",
4471 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength + ConstLowerBound);
4477 if (
auto *VAT =
C.getAsVariableArrayType(ArrayTy)) {
4478 Length = VAT->getSizeExpr();
4479 if (std::optional<llvm::APSInt> L = Length->getIntegerConstantExpr(
C)) {
4484 auto *CAT =
C.getAsConstantArrayType(ArrayTy);
4485 assert(CAT &&
"unexpected type for array initializer");
4486 ConstLength = CAT->getSize();
4489 auto *LengthVal =
Builder.CreateIntCast(
4491 Length->getType()->hasSignedIntegerRepresentation());
4493 LengthVal, llvm::ConstantInt::get(
IntPtrTy, 1),
"len_sub_1",
4498 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength);
4507 if (
auto *VLA =
getContext().getAsVariableArrayType(ResultExprTy)) {
4513 BaseTy, VLA->getElementType(), IsLowerBound);
4522 Idx =
Builder.CreateMul(Idx, NumElements);
4524 Idx =
Builder.CreateNSWMul(Idx, NumElements);
4533 assert(Array->getType()->isArrayType() &&
4534 "Array to pointer decay must have array source type!");
4538 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
4545 *
this, ArrayLV.
getAddress(*
this), {CGM.getSize(CharUnits::Zero()), Idx},
4546 ResultExprTy, !
getLangOpts().isSignedOverflowDefined(),
4553 ResultExprTy, IsLowerBound);
4576 Base.getQuals().removeObjCGCAttr();
4585 "Result must be a vector");
4602 if (
Base.isSimple()) {
4603 llvm::Constant *CV =
4608 assert(
Base.isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
4610 llvm::Constant *BaseElts =
Base.getExtVectorElts();
4613 for (
unsigned i = 0, e = Indices.size(); i != e; ++i)
4614 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
4615 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
4637 SkippedChecks.
set(SanitizerKind::Alignment,
true);
4638 if (IsBaseCXXThis || isa<DeclRefExpr>(BaseExpr))
4639 SkippedChecks.
set(SanitizerKind::Null,
true);
4647 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
4662 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
4665 llvm_unreachable(
"Unhandled member declaration!");
4672 llvm::Value *ThisValue) {
4673 bool HasExplicitObjectParameter =
false;
4674 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
CurCodeDecl)) {
4675 HasExplicitObjectParameter = MD->isExplicitObjectMemberFunction();
4676 assert(MD->getParent()->isLambda());
4677 assert(MD->getParent() ==
Field->getParent());
4680 if (HasExplicitObjectParameter) {
4682 auto It = LocalDeclMap.find(D);
4683 assert(It != LocalDeclMap.end() &&
"explicit parameter not loaded?");
4684 Address AddrOfExplicitObject = It->getSecond();
4705 unsigned FieldIndex) {
4706 unsigned I = 0, Skipped = 0;
4709 if (I == FieldIndex)
4711 if (F->isUnnamedBitField())
4716 return FieldIndex - Skipped;
4725 if (Offset.isZero())
4766 if (RD->isDynamicClass())
4769 for (
const auto &
Base : RD->bases())
4816 llvm::Type *FieldIntTy = llvm::Type::getIntNTy(
getLLVMContext(), SS);
4852 assert(!FieldTBAAInfo.
Offset &&
4853 "Nonzero offset for an access with no base type!");
4866 FieldTBAAInfo.
Size =
4873 if (
auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) {
4875 ClassDef->isDynamicClass()) {
4936 if (field->
hasAttr<AnnotateAttr>())
4961 V =
V.withElementType(llvmType);
5006 assert(E->
isTransparent() &&
"non-transparent glvalue init list");
5014 const Expr *Operand) {
5015 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->IgnoreParens())) {
5017 return std::nullopt;
5026std::optional<LValue> HandleConditionalOperatorLValueSimpleCase(
5033 std::swap(Live, Dead);
5041 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Live->
IgnoreParens())) {
5043 llvm::Type *ElemTy = CGF.
ConvertType(Dead->getType());
5052 return std::nullopt;
5054struct ConditionalInfo {
5055 llvm::BasicBlock *lhsBlock, *rhsBlock;
5056 std::optional<LValue> LHS, RHS;
5061template<
typename FuncTy>
5064 const FuncTy &BranchGenFunc) {
5070 CodeGenFunction::ConditionalEvaluation eval(CGF);
5080 Info.lhsBlock = CGF.
Builder.GetInsertBlock();
5083 CGF.
Builder.CreateBr(endBlock);
5090 Info.rhsBlock = CGF.
Builder.GetInsertBlock();
5102 "Unexpected conditional operator!");
5106 OpaqueValueMapping binding(*
this, E);
5107 if (HandleConditionalOperatorLValueSimpleCase(*
this, E))
5117 if (!
expr->isGLValue()) {
5120 "Unexpected conditional operator!");
5124 OpaqueValueMapping binding(*
this,
expr);
5125 if (std::optional<LValue> Res =
5126 HandleConditionalOperatorLValueSimpleCase(*
this,
expr))
5129 ConditionalInfo Info = EmitConditionalBlocks(
5134 if ((Info.LHS && !Info.LHS->isSimple()) ||
5135 (Info.RHS && !Info.RHS->isSimple()))
5138 if (Info.LHS && Info.RHS) {
5139 Address lhsAddr = Info.LHS->getAddress(*
this);
5140 Address rhsAddr = Info.RHS->getAddress(*
this);
5142 lhsAddr, rhsAddr, Info.lhsBlock, Info.rhsBlock,
5145 std::max(Info.LHS->getBaseInfo().getAlignmentSource(),
5146 Info.RHS->getBaseInfo().getAlignmentSource());
5148 Info.LHS->getTBAAInfo(), Info.RHS->getTBAAInfo());
5152 assert((Info.LHS || Info.RHS) &&
5153 "both operands of glvalue conditional are throw-expressions?");
5154 return Info.LHS ? *Info.LHS : *Info.RHS;
5169 case CK_LValueToRValueBitCast:
5170 case CK_ArrayToPointerDecay:
5171 case CK_FunctionToPointerDecay:
5172 case CK_NullToMemberPointer:
5173 case CK_NullToPointer:
5174 case CK_IntegralToPointer:
5175 case CK_PointerToIntegral:
5176 case CK_PointerToBoolean:
5177 case CK_IntegralCast:
5178 case CK_BooleanToSignedIntegral:
5179 case CK_IntegralToBoolean:
5180 case CK_IntegralToFloating:
5181 case CK_FloatingToIntegral:
5182 case CK_FloatingToBoolean:
5183 case CK_FloatingCast:
5184 case CK_FloatingRealToComplex:
5185 case CK_FloatingComplexToReal:
5186 case CK_FloatingComplexToBoolean:
5187 case CK_FloatingComplexCast:
5188 case CK_FloatingComplexToIntegralComplex:
5189 case CK_IntegralRealToComplex:
5190 case CK_IntegralComplexToReal:
5191 case CK_IntegralComplexToBoolean:
5192 case CK_IntegralComplexCast:
5193 case CK_IntegralComplexToFloatingComplex:
5194 case CK_DerivedToBaseMemberPointer:
5195 case CK_BaseToDerivedMemberPointer:
5196 case CK_MemberPointerToBoolean:
5197 case CK_ReinterpretMemberPointer:
5198 case CK_AnyPointerToBlockPointerCast:
5199 case CK_ARCProduceObject:
5200 case CK_ARCConsumeObject:
5201 case CK_ARCReclaimReturnedObject:
5202 case CK_ARCExtendBlockObject:
5203 case CK_CopyAndAutoreleaseBlockObject:
5204 case CK_IntToOCLSampler:
5205 case CK_FloatingToFixedPoint:
5206 case CK_FixedPointToFloating:
5207 case CK_FixedPointCast:
5208 case CK_FixedPointToBoolean:
5209 case CK_FixedPointToIntegral:
5210 case CK_IntegralToFixedPoint:
5212 case CK_HLSLVectorTruncation:
5213 case CK_HLSLArrayRValue:
5217 llvm_unreachable(
"dependent cast kind in IR gen!");
5219 case CK_BuiltinFnToFnPtr:
5220 llvm_unreachable(
"builtin functions are handled elsewhere");
5223 case CK_NonAtomicToAtomic:
5224 case CK_AtomicToNonAtomic:
5230 const auto *DCE = cast<CXXDynamicCastExpr>(E);
5234 case CK_ConstructorConversion:
5235 case CK_UserDefinedConversion:
5236 case CK_CPointerToObjCPointerCast:
5237 case CK_BlockPointerToObjCPointerCast:
5238 case CK_LValueToRValue:
5253 if (
V.getElementType() !=
T)
5260 case CK_UncheckedDerivedToBase:
5261 case CK_DerivedToBase: {
5262 const auto *DerivedClassTy =
5264 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->getDecl());
5282 case CK_BaseToDerived: {
5284 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->getDecl());
5299 if (
SanOpts.
has(SanitizerKind::CFIDerivedCast))
5307 case CK_LValueBitCast: {
5309 const auto *CE = cast<ExplicitCastExpr>(E);
5316 if (
SanOpts.
has(SanitizerKind::CFIUnrelatedCast))
5324 case CK_AddressSpaceConversion: {
5335 case CK_ObjCObjectLValueCast: {
5341 case CK_ZeroToOCLOpaqueType:
5342 llvm_unreachable(
"NULL to OpenCL opaque type lvalue cast is not valid");
5344 case CK_VectorSplat: {
5352 llvm_unreachable(
"Unhandled lvalue cast kind?");
5364 llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
5365 it = OpaqueLValues.find(e);
5367 if (it != OpaqueLValues.end())
5370 assert(e->
isUnique() &&
"LValue for a nonunique OVE hasn't been emitted");
5378 llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
5379 it = OpaqueRValues.find(e);
5381 if (it != OpaqueRValues.end())
5384 assert(e->
isUnique() &&
"RValue for a nonunique OVE hasn't been emitted");
5409 llvm_unreachable(
"bad evaluation kind");
5422 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
5425 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
5430 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
5431 if (
const auto *MD =
5432 dyn_cast_if_present<CXXMethodDecl>(CE->getCalleeDecl());
5433 MD && MD->isImplicitObjectMemberFunction())
5462 if (!PD->isInlineBuiltinDeclaration())
5471 std::string NoBuiltinFD = (
"no-builtin-" + FD->
getName()).str();
5472 std::string NoBuiltins =
"no-builtins";
5475 std::string FDInlineName = (Ident +
".inline").str();
5477 bool IsPredefinedLibFunction =
5479 bool HasAttributeNoBuiltin =
5480 CGF.
CurFn->getAttributes().hasFnAttr(NoBuiltinFD) ||
5481 CGF.
CurFn->getAttributes().hasFnAttr(NoBuiltins);
5485 if (CGF.
CurFn->getName() != FDInlineName &&
5488 llvm::Function *Fn = llvm::cast<llvm::Function>(CalleePtr);
5489 llvm::Module *M = Fn->getParent();
5490 llvm::Function *Clone = M->getFunction(FDInlineName);
5492 Clone = llvm::Function::Create(Fn->getFunctionType(),
5493 llvm::GlobalValue::InternalLinkage,
5494 Fn->getAddressSpace(), FDInlineName, M);
5495 Clone->addFnAttr(llvm::Attribute::AlwaysInline);
5506 else if (!IsPredefinedLibFunction || !HasAttributeNoBuiltin)
5512 FD->
hasAttr<CUDAGlobalAttr>())
5514 cast<llvm::GlobalValue>(CalleePtr->stripPointerCasts()));
5523 if (
auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
5524 if (ICE->getCastKind() == CK_FunctionToPointerDecay ||
5525 ICE->getCastKind() == CK_BuiltinFnToFnPtr) {
5530 }
else if (
auto DRE = dyn_cast<DeclRefExpr>(E)) {
5531 if (
auto FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
5534 }
else if (
auto ME = dyn_cast<MemberExpr>(E)) {
5535 if (
auto FD = dyn_cast<FunctionDecl>(ME->
getMemberDecl())) {
5541 }
else if (
auto NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
5545 }
else if (
auto PDE = dyn_cast<CXXPseudoDestructorExpr>(E)) {
5550 llvm::Value *calleePtr;
5562 if (
const auto *VD =
5567 CGCallee callee(calleeInfo, calleePtr);
5583 assert(E->
getOpcode() == BO_Assign &&
"unexpected binary l-value");
5625 llvm::Value *
Result =
nullptr;
5628 if (
SanOpts.
has(SanitizerKind::ImplicitBitfieldConversion))
5654 llvm_unreachable(
"bad evaluation kind");
5665 "Can't have a scalar return unless the return type is a "
5678 &&
"binding l-value to type which needs a temporary");
5716 "Can't have a scalar return unless the return type is a "
5738 return Builder.CreateZExtOrTrunc(OffsetValue,
5743 llvm::Value *BaseValue,
5745 unsigned CVRQualifiers) {
5747 Ivar, CVRQualifiers);
5752 llvm::Value *BaseValue =
nullptr;
5763 ObjectTy = BaseExpr->
getType();
5783 llvm::Value *Chain) {
5787 "Call must have function pointer type!");
5789 const Decl *TargetDecl =
5792 assert((!isa_and_present<FunctionDecl>(TargetDecl) ||
5793 !cast<FunctionDecl>(TargetDecl)->isImmediateFunction()) &&
5794 "trying to emit a call to an immediate function");
5798 auto PointeeType = cast<PointerType>(CalleeType)->getPointeeType();
5803 (!TargetDecl || !isa<FunctionDecl>(TargetDecl)) &&
5804 !isa<FunctionNoProtoType>(PointeeType)) {
5805 if (llvm::Constant *PrefixSig =
5807 SanitizerScope SanScope(
this);
5810 llvm::Type *PrefixSigType = PrefixSig->getType();
5811 llvm::StructType *PrefixStructTy = llvm::StructType::get(
5814 llvm::Value *CalleePtr =
Callee.getFunctionPointer();
5825 llvm::Value *AlignedCalleePtr;
5827 llvm::Value *CalleeAddress =
5829 llvm::Value *Mask = llvm::ConstantInt::get(
IntPtrTy, ~1);
5830 llvm::Value *AlignedCalleeAddress =
5831 Builder.CreateAnd(CalleeAddress, Mask);
5833 Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());
5835 AlignedCalleePtr = CalleePtr;
5838 llvm::Value *CalleePrefixStruct = AlignedCalleePtr;
5839 llvm::Value *CalleeSigPtr =
5841 llvm::Value *CalleeSig =
5843 llvm::Value *CalleeSigMatch =
Builder.CreateICmpEQ(CalleeSig, PrefixSig);
5847 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
5854 llvm::Value *CalleeTypeHashMatch =
5855 Builder.CreateICmpEQ(CalleeTypeHash, TypeHash);
5858 EmitCheck(std::make_pair(CalleeTypeHashMatch, SanitizerKind::Function),
5859 SanitizerHandler::FunctionTypeMismatch, StaticData,
5867 const auto *FnType = cast<FunctionType>(PointeeType);
5872 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
5873 SanitizerScope SanScope(
this);
5882 llvm::Value *TypeId = llvm::MetadataAsValue::get(
getLLVMContext(), MD);
5884 llvm::Value *CalleePtr =
Callee.getFunctionPointer();
5885 llvm::Value *TypeTest =
Builder.CreateCall(
5889 llvm::Constant *StaticData[] = {
5896 CalleePtr, StaticData);
5898 EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIICall),
5899 SanitizerHandler::CFICheckFail, StaticData,
5900 {CalleePtr, llvm::UndefValue::get(
IntPtrTy)});
5915 bool StaticOperator =
false;
5916 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
5917 if (OCE->isAssignmentOp())
5920 switch (OCE->getOperator()) {
5922 case OO_GreaterGreater:
5934 if (
const auto *MD =
5935 dyn_cast_if_present<CXXMethodDecl>(OCE->getCalleeDecl());
5936 MD && MD->isStatic())
5937 StaticOperator =
true;
5941 if (StaticOperator) {
5947 EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), Arguments,
5951 Args, FnType, Chain);
5973 if (isa<FunctionNoProtoType>(FnType) || Chain) {
5975 int AS =
Callee.getFunctionPointer()->getType()->getPointerAddressSpace();
5976 CalleeTy = CalleeTy->getPointerTo(AS);
5978 llvm::Value *CalleePtr =
Callee.getFunctionPointer();
5979 CalleePtr =
Builder.CreateBitCast(CalleePtr, CalleeTy,
"callee.knr.cast");
5980 Callee.setFunctionPointer(CalleePtr);
5987 isa<CUDAKernelCallExpr>(E) &&
5988 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
5989 llvm::Value *Handle =
Callee.getFunctionPointer();
5994 llvm::CallBase *CallOrInvoke =
nullptr;
6001 if (
auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
6004 DI->EmitFuncDeclForCallSite(CallOrInvoke,
6005 DI->getFunctionType(CalleeDecl, ResTy, Args),
6031 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
6048 llvm_unreachable(
"bad evaluation kind");
6052 assert(Val->getType()->isFPOrFPVectorTy());
6053 if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
6057 llvm::MDNode *
Node = MDHelper.createFPMath(Accuracy);
6059 cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath,
Node);
6063 llvm::Type *EltTy = Val->getType()->getScalarType();
6064 if (!EltTy->isFloatTy())
6084 llvm::Type *EltTy = Val->getType()->getScalarType();
6085 if (!EltTy->isFloatTy())
6105 struct LValueOrRValue {
6119 LValueOrRValue result;
6123 const Expr *semantic = *i;
6127 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
6129 if (ov->isUnique()) {
6130 assert(ov != resultExpr &&
6131 "A unique OVE cannot be used as the result expression");
6137 typedef CodeGenFunction::OpaqueValueMappingData OVMA;
6139 if (ov == resultExpr && ov->
isPRValue() && !forLValue &&
6144 opaqueData = OVMA::bind(CGF, ov, LV);
6149 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
6152 if (ov == resultExpr) {
6160 opaques.push_back(opaqueData);
6164 }
else if (semantic == resultExpr) {
6177 for (
unsigned i = 0, e = opaques.size(); i != e; ++i)
6178 opaques[i].unbind(CGF);
Defines the clang::ASTContext interface.
Defines enum values for all the target-independent builtin functions.
CodeGenFunction::ComplexPairTy ComplexPairTy
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 const Expr * isSimpleArrayDecayOperand(const Expr *E)
isSimpleArrayDecayOperand - If the specified expr is a simple decay from an array to pointer,...
static llvm::cl::opt< bool > ClSanitizeGuardChecks("ubsan-guard-checks", llvm::cl::Optional, llvm::cl::desc("Guard UBSAN checks with `llvm.allow.ubsan.check()`."))
static bool hasBooleanRepresentation(QualType Ty)
static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind)
static bool hasBPFPreserveStaticOffset(const RecordDecl *D)
static Address emitAddrOfFieldStorage(CodeGenFunction &CGF, Address base, const FieldDecl *field)
Drill down to the storage of a field without walking into reference types.
ConstantEmissionKind
Can we constant-emit a load of a reference to a variable of the given type? This is different from pr...
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 llvm::Value * emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, llvm::Value *High)
Emit the hash_16_bytes function from include/llvm/ADT/Hashing.h.
static QualType getFixedSizeElementType(const ASTContext &ctx, const VariableArrayType *vla)
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 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")
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 DeclRefExpr * tryToConvertMemberExprToDeclRefExpr(CodeGenFunction &CGF, const MemberExpr *ME)
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 QualType getConstantExprReferredType(const FullExpr *E, const ASTContext &Ctx)
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 bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *FD, RecIndicesTy &Indices)
static LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc)
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 getFieldOffsetInBits(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *FD, int64_t &Offset)
The offset of a field from the beginning of the record.
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...
static CharUnits getArrayElementAlign(CharUnits arrayAlign, llvm::Value *idx, CharUnits eltSize)
static llvm::cl::opt< bool > ClSanitizeDebugDeoptimization("ubsan-unique-traps", llvm::cl::Optional, llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."))
static RawAddress createReferenceTemporary(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *Inner, RawAddress *Alloca=nullptr)
static bool isAAPCS(const TargetInfo &TargetInfo)
Helper method to check if the underlying ABI is AAPCS.
static void EmitStoreOfMatrixScalar(llvm::Value *value, LValue lvalue, bool isInit, CodeGenFunction &CGF)
static llvm::Constant * EmitFunctionDeclPointer(CodeGenModule &CGM, GlobalDecl GD)
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 Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base, const FieldDecl *Field)
Get the address of a zero-sized field within a record.
static void emitCheckHandlerCall(CodeGenFunction &CGF, llvm::FunctionType *FnType, ArrayRef< llvm::Value * > FnArgs, SanitizerHandler CheckHandler, CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB)
static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base, LValueBaseInfo &BaseInfo, TBAAAccessInfo &TBAAInfo, QualType BaseTy, QualType ElTy, bool IsLowerBound)
static void pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *E, Address ReferenceTemporary)
llvm::MachO::Record Record
static const SanitizerMask AlwaysRecoverable
static const SanitizerMask Unrecoverable
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType.
Defines the SourceManager interface.
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.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
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>.
const NoSanitizeList & getNoSanitizeList() const
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.
unsigned getTargetAddressSpace(LangAS AS) const
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 ?: operator.
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
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 isDynamicClass() const
bool hasDefinition() const
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 LLVM_READONLY
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
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.
SanitizerSet SanitizeTrap
Set of sanitizer checks that trap rather than diagnose.
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
std::string TrapFuncName
If not an empty string, trap intrinsics are lowered to calls to this function instead of to trap inst...
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.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
Address setKnownNonNull()
void setAlignment(CharUnits Value)
void replaceBasePointer(llvm::Value *P)
This function is used in situations where the caller is doing some sort of opaque "laundering" of the...
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 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 debug location to the specified location or preferred location of ...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
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 CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, 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 CreatePreserveStructAccessIndex(Address Addr, unsigned Index, unsigned FieldIndex, llvm::MDNode *DbgInfo)
Address CreateLaunderInvariantGroup(Address Addr)
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Address CreatePreserveUnionAccessIndex(Address Addr, unsigned FieldIndex, llvm::MDNode *DbgInfo)
Address CreateStripInvariantGroup(Address Addr)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const 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 llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
Determine if a member pointer is non-null. Returns an i1.
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
MangleContext & getMangleContext()
Gets the mangle context.
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::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
CGFunctionInfo - Class to encapsulate the information about a function definition.
virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, llvm::Value *ivarOffset)=0
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)=0
virtual llvm::Value * EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)=0
virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, Address AddrWeakObj)=0
virtual Address GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel)=0
Get the address of a selector for the specified name and type values.
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, bool threadlocal=false)=0
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.
bool isNontemporalDecl(const ValueDecl *VD) const
Checks if the VD variable is marked as nontemporal declaration in current context.
virtual void checkAndEmitLastprivateConditional(CodeGenFunction &CGF, const Expr *LHS)
Checks if the provided LVal is lastprivate conditional and emits the code to update the value of the ...
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.
CallArgList - Type for representing both the value and type of arguments in a call.
void add(RValue rvalue, QualType type)
virtual llvm::Value * getContextValue() const
virtual const FieldDecl * lookup(const VarDecl *VD) const
Lookup the captured field decl for a variable.
static ConstantEmission forValue(llvm::Constant *C)
static ConstantEmission forReference(llvm::Constant *C)
static bool shouldBindAsLValue(const Expr *expr)
static bool shouldBindAsLValue(const Expr *expr)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
RValue EmitLoadOfGlobalRegLValue(LValue LV)
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
llvm::Value * EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr)
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
llvm::Value * EmitNonNullRValueCheck(RValue RV, QualType T)
Create a check that a scalar RValue is non-null.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
LValue EmitCastLValue(const CastExpr *E)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
SanitizerSet SanOpts
Sanitizers enabled for this function.
LValue EmitCoawaitLValue(const CoawaitExpr *E)
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
llvm::Value * EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
CGCapturedStmtInfo * CapturedStmtInfo
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
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.
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.
bool inSuspendBlock() const
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Load a pointer with type PtrTy stored at address Ptr.
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
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.
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
llvm::Value * EmitIvarOffset(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
llvm::Value * EmitARCLoadWeakRetained(Address addr)
const LangOptions & getLangOpts() const
llvm::Value * LoadPassedObjectSize(const Expr *E, QualType EltTy)
If E references a parameter with pass_object_size info or a constant array size modifier,...
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
LValue EmitInitListLValue(const InitListExpr *E)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
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...
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.
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Address EmitExtVectorElementLValue(LValue V)
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...
@ 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.
void SetDivFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
LValue EmitCallExprLValue(const CallExpr *E)
LValue EmitUnsupportedLValue(const Expr *E, const char *Name)
EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
llvm::Type * ConvertTypeForMem(QualType T)
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex)
Get the record field index as represented in debug info.
LValue EmitLValueForField(LValue Base, const FieldDecl *Field)
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...
static Destroyer destroyCXXObject
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
@ Default
! No language constraints on evaluation order.
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr)
llvm::Value * EmitARCLoadWeak(Address addr)
const TargetInfo & getTarget() const
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
LValue EmitVAArgExprLValue(const VAArgExpr *E)
bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, SourceLocation Loc)
Check if the scalar Value is within the valid range for the given type Ty.
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
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...
llvm::Value * EmitCountedByFieldExpr(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)
Build an expression accessing the "counted_by" field.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
Address mergeAddressesInConditionalExpr(Address LHS, Address RHS, llvm::BasicBlock *LHSBlock, llvm::BasicBlock *RHSBlock, llvm::BasicBlock *MergeBlock, QualType MergedType)
LValue EmitUnaryOpLValue(const UnaryOperator *E)
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
RValue EmitUnsupportedRValue(const Expr *E, const char *Name)
EmitUnsupportedRValue - Emit a dummy r-value using the type of E and issue an ErrorUnsupported style ...
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)
getAccessedFieldNo - Given an encoded value and a result number, return the input field number being ...
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
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.
void EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::Value *Index, QualType IndexType, QualType IndexedType, bool Accessed)
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.
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
RValue EmitLoadOfExtVectorElementLValue(LValue V)
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
CGDebugInfo * getDebugInfo()
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
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...
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
Address emitAddrOfImagComponent(Address complex, QualType complexType)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
const TargetCodeGenInfo & getTargetHooks() const
llvm::Value * emitBoolVecConversion(llvm::Value *SrcVec, unsigned NumElementsDst, const llvm::Twine &Name="")
LValue MakeNaturalAlignRawAddrLValue(llvm::Value *V, QualType T)
LValue EmitPredefinedLValue(const PredefinedExpr *E)
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst)
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
void SetSqrtFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
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...
CGCallee EmitCallee(const Expr *E)
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.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
llvm::Instruction * getPostAllocaInsertPoint()
Return PostAllocaInsertPt.
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 EmitMemberExpr(const MemberExpr *E)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
llvm::ConstantInt * getUBSanFunctionTypeHash(QualType T) const
Return a type hash constant for a function instrumented by -fsanitize=function.
static Destroyer destroyARCWeak
llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields
CleanupKind getCleanupKind(QualType::DestructionKind kind)
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
llvm::Type * ConvertType(QualType T)
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Address GetAddrOfBlockDecl(const VarDecl *var)
CodeGenTypes & getTypes() const
void EmitARCInitWeak(Address addr, llvm::Value *value)
LValue EmitArraySectionExpr(const ArraySectionExpr *E, bool IsLowerBound=true)
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E)
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Address EmitCXXUuidofExpr(const CXXUuidofExpr *E)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, LValue LV, QualType Type, SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
LValue EmitStringLiteralLValue(const StringLiteral *E)
static Destroyer destroyARCStrongPrecise
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
Address LoadCXXThisAddress()
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 * 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...
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E)
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
static bool hasAggregateEvaluationKind(QualType T)
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
RawAddress CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
const FieldDecl * FindCountedByField(const FieldDecl *FD)
Find the FieldDecl specified in a FAM's "counted_by" attribute.
void SetFPAccuracy(llvm::Value *Val, float Accuracy)
SetFPAccuracy - Set the minimum required accuracy of the given floating point operation,...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
const CallExpr * MustTailCall
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
void EmitCfiSlowPathCheck(SanitizerMask Kind, 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.
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
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...
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
static Destroyer destroyARCStrongImprecise
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E)
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)
LValue EmitStmtExprLValue(const StmtExpr *E)
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
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 ...
llvm::LLVMContext & getLLVMContext()
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
bool LValueIsSuitableForInlineAtomic(LValue Src)
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Address emitAddrOfRealComponent(Address complex, QualType complexType)
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E)
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...
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E)
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
LValue EmitLValueForLambdaField(const FieldDecl *Field)
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
This class organizes the cross-function state that is used while generating LLVM code.
ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD)
Get the address of a GUID.
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
void setDSOLocal(llvm::GlobalValue *GV) const
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()
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression.
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C)
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
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.
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
DiagnosticsEngine & getDiags() const
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()
const TargetInfo & getTarget() const
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
llvm::Constant * getTypeDescriptorFromMap(QualType Ty)
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
const llvm::DataLayout & getDataLayout() const
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.
SanitizerMetadata * getSanitizerMetadata()
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
const llvm::Triple & getTriple() const
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType)
getTBAAInfoForSubobject - Get TBAA information for an access with a given base lvalue.
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type.
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
ASTContext & getContext() const
ConstantAddress GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO)
Get the address of a template parameter object.
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.
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purposes of conditional ope...
llvm::LLVMContext & getLLVMContext()
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
CharUnits getMinimumObjectSize(QualType Ty)
Returns the minimum object size for an object of the given type.
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character.
void setCurrentStmt(const Stmt *S)
If the execution count for the current statement is known, record that as the current count.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
const llvm::DataLayout & getDataLayout() const
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments.
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
A specialization of Address that requires the address to be an LLVM Constant.
ConstantAddress withElementType(llvm::Type *ElemTy) const
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.
llvm::Constant * tryEmitConstantExpr(const ConstantExpr *CE)
FunctionArgList - Type for representing both the decl and type of parameters to a function.
void mergeForCast(const LValueBaseInfo &Info)
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)
void setObjCIvar(bool Value)
bool isObjCStrong() const
bool isGlobalObjCRef() const
void setObjCArray(bool Value)
bool isVolatileQualified() const
llvm::Value * getMatrixIdx() const
Address getAddress(CodeGenFunction &CGF) 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)
unsigned getVRQualifiers() const
void setThreadLocalRef(bool Value)
void setGlobalObjCRef(bool Value)
bool isExtVectorElt() const
llvm::Value * getVectorIdx() const
void setNontemporal(bool Value)
LValueBaseInfo getBaseInfo() const
llvm::Value * getPointer(CodeGenFunction &CGF) 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)
void setBaseIvarExp(Expr *V)
RValue asAggregateRValue(CodeGenFunction &CGF) const
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.
RawAddress withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::Value * getPointer() const
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const
Return a constant used by UBSan as a signature to identify functions possessing type information,...
Complex values, per C99 6.2.5p11.
QualType getElementType() const
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumRows() const
Returns the number of rows in the matrix.
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this 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
Decl - This represents one declaration (or definition), e.g.
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()
void ConvertArgToString(ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, ArrayRef< intptr_t > QualTypeVals) const
Converts a diagnostic argument (as an intptr_t) into the string that represents it.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const
Calculates the [Min,Max) values the enum can store based on the NumPositiveBits and NumNegativeBits.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
EnumDecl * getDecl() const
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 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 isFlexibleArrayMemberLike(ASTContext &Context, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution=false) const
Check whether this array fits the idiom of a flexible array member, depending on the value of -fstric...
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.
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
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.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
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
SanitizerSet Sanitize
Set of enabled sanitizers.
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
unsigned getBlockId(const BlockDecl *BD, bool Local)
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? This is only meaningful if the named memb...
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.
bool containsType(SanitizerMask Mask, StringRef MangledTypeName, StringRef Category=StringRef()) const
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
Represents a class type in Objective C.
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 ...
ParenExpr - This represents a parethesized expression, e.g.
const Expr * getSubExpr() const
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.
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)
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.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Scope - A scope is a transient data structure that is used while parsing the program.
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;}).
Stmt - This represents one statement.
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.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBlockPointerType() const
bool isBooleanType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool hasAttr(attr::Kind AK) const
Determine whether this type had the specified attribute applied to it (looking through top-level type...
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
bool isFunctionPointerType() const
bool isCountAttributedType() 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 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 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 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 isFloatingType() 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
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
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...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
@ 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
Matches all kinds of arrays.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
bool This(InterpState &S, CodePtr OpPC)
bool Zero(InterpState &S, CodePtr OpPC)
bool Load(InterpState &S, CodePtr OpPC)
bool Cast(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ 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.
@ Dtor_Complete
Complete object dtor.
llvm::hash_code hash_value(const CustomizableOptional< T > &O)
const FunctionProtoType * T
LangAS getLangASFromTargetAS(unsigned TargetAS)
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ 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.
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