clang: lib/CodeGen/CGExpr.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

34#include "llvm/ADT/STLExtras.h"

35#include "llvm/ADT/ScopeExit.h"

36#include "llvm/ADT/StringExtras.h"

37#include "llvm/IR/DataLayout.h"

38#include "llvm/IR/Intrinsics.h"

39#include "llvm/IR/LLVMContext.h"

40#include "llvm/IR/MDBuilder.h"

41#include "llvm/IR/MatrixBuilder.h"

42#include "llvm/Support/ConvertUTF.h"

43#include "llvm/Support/Endian.h"

44#include "llvm/Support/MathExtras.h"

45#include "llvm/Support/Path.h"

46#include "llvm/Support/xxhash.h"

47#include "llvm/Transforms/Utils/SanitizerStats.h"

48

49#include

50#include

51#include

52

53using namespace clang;

54using namespace CodeGen;

55

57

58

60 "ubsan-guard-checks", llvm:🆑:Optional,

61 llvm:🆑:desc("Guard UBSAN checks with `llvm.allow.ubsan.check()`."));

62}

63

64

65

66

67

68

70

72

74

76

79

80

81

82

83

84

85

87CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits Align,

88 const Twine &Name,

89 llvm::Value *ArraySize) {

91 Alloca->setAlignment(Align.getAsAlign());

93}

94

95

96

98 const Twine &Name,

99 llvm::Value *ArraySize,

102 if (AllocaAddr)

103 *AllocaAddr = Alloca;

104 llvm::Value *V = Alloca.getPointer();

105

106

107

108

111 llvm::IRBuilderBase::InsertPointGuard IPG(Builder);

112

113

114

115 if (!ArraySize)

119 Builder.getPtrTy(DestAddrSpace), true);

120 }

121

123}

124

125

126

127

129 const Twine &Name,

130 llvm::Value *ArraySize) {

131 llvm::AllocaInst *Alloca;

132 if (ArraySize)

133 Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);

134 else

135 Alloca =

136 new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),

138 if (Allocas) {

139 Allocas->Add(Alloca);

140 }

141 return Alloca;

142}

143

144

145

146

147

149 const Twine &Name) {

153}

154

158}

159

162

164}

165

167 const Twine &Name,

170 nullptr, Alloca);

171

173 auto *ArrayTy = castllvm::ArrayType(Result.getElementType());

174 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),

175 ArrayTy->getNumElements());

176

179 }

181}

182

185 const Twine &Name) {

187}

188

190 const Twine &Name) {

192 Name);

193}

194

195

196

202 }

203

206 CGFPOptionsRAII FPOptsRAII(*this, E);

209

212}

213

214

215

219

220

221

222

223

224 if (const auto *CondOp = dyn_cast(

226 if (CondOp->getObjectKind() == OK_BitField)

228 }

229

230

232}

233

234

235

236

237

240 bool ignoreResult) {

247 if (!ignoreResult && aggSlot.isIgnored())

251 }

252 llvm_unreachable("bad evaluation kind");

253}

254

255

256

259

263}

264

265

266

270 bool IsInit) {

271

275 false);

276 return;

277

284 return;

285 }

286

291 return;

292 }

293 }

294 llvm_unreachable("bad evaluation kind");

295}

296

303 return;

309 return;

312 EmitScalarInit(E, nullptr, LV, false);

313 else

315 return;

316 }

317 llvm_unreachable("bad evaluation kind");

318}

319

320static void

323

324

325

326

327

329 switch (Lifetime) {

332

333 break;

334

336

337 return;

338

343

344

345 return;

346

348

349 return;

350

357 bool Precise = isa_and_nonnull(VD) &&

358 VD->hasAttr();

362 } else {

363

364

367 }

372 else

376 return;

377

379 llvm_unreachable("temporary cannot have dynamic storage duration");

380 }

381 llvm_unreachable("unknown storage duration");

382 }

383 }

384

388

389 auto *ClassDecl = cast(RT->getDecl());

390 if (!ClassDecl->hasTrivialDestructor())

391 ReferenceTemporaryDtor = ClassDecl->getDestructor();

392 }

393

394 if (!ReferenceTemporaryDtor)

395 return;

396

397

401 llvm::FunctionCallee CleanupFn;

402 llvm::Constant *CleanupArg;

405 ReferenceTemporary, E->getType(),

408 CleanupArg = llvm::Constant::getNullValue(CGF.Int8PtrTy);

409 } else {

412 CleanupArg = castllvm::Constant(ReferenceTemporary.emitRawPointer(CGF));

413 }

415 CGF, *cast(M->getExtendingDecl()), CleanupFn, CleanupArg);

416 break;

417 }

418

423 break;

424

427 ReferenceTemporary, E->getType(),

430 break;

431

433 llvm_unreachable("temporary cannot have dynamic storage duration");

434 }

435}

436

439 const Expr *Inner,

445

446

447

448

449 QualType Ty = Inner->getType();

455 auto *GV = new llvm::GlobalVariable(

457 llvm::GlobalValue::PrivateLinkage, Init, ".ref.tmp", nullptr,

458 llvm::GlobalValue::NotThreadLocal,

461 GV->setAlignment(alignment.getAsAlign());

462 llvm::Constant *C = GV;

464 C = TCG.performAddrSpaceCast(

466 llvm::PointerType::get(

469

470 return RawAddress(C, GV->getValueType(), alignment);

471 }

473 }

477

479 llvm_unreachable("temporary can't have dynamic storage duration");

480 }

481 llvm_unreachable("unknown storage duration");

482}

483

484

487}

488

492

494 !cast(M->getExtendingDecl())->isARCPseudoStrong()) &&

495 "Reference should never be pseudo-strong!");

496

497

498

503 if (auto *Var = dyn_castllvm::GlobalVariable(Object.getPointer())) {

506

507

508

509

510

511

512

513 if (Var->hasInitializer())

515

517 }

520

522 default: llvm_unreachable("expected scalar or aggregate expression");

525 break;

533 break;

534 }

535 }

536

538 return RefTempDst;

539 }

540

544

545 for (const auto &Ignored : CommaLHSs)

547

548 if (const auto *opaque = dyn_cast(E)) {

549 if (opaque->getType()->isRecordType()) {

550 assert(Adjustments.empty());

552 }

553 }

554

555

558 if (auto *Var = dyn_castllvm::GlobalVariable(

559 Object.getPointer()->stripPointerCasts())) {

561 Object = Object.withElementType(TemporaryType);

562

563

564

565 if (!Var->hasInitializer()) {

568 }

569 } else {

576 Alloca, Size);

577 }

578 break;

579

581 if (!ShouldEmitLifetimeMarkers)

582 break;

583

584

585

586

587

588

589

590

591 ConditionalEvaluation *OldConditional = nullptr;

592 CGBuilderTy::InsertPoint OldIP;

594 ((SanOpts.has(SanitizerKind::HWAddress) &&

595 SanOpts.has(SanitizerKind::Memory) &&

598 OldConditional = OutermostConditional;

599 OutermostConditional = nullptr;

600

601 OldIP = Builder.saveIP();

602 llvm::BasicBlock *Block = OldConditional->getStartingBlock();

603 Builder.restoreIP(CGBuilderTy::InsertPoint(

604 Block, llvm::BasicBlock::iterator(Block->back())));

605 }

606

611 Size);

612 }

613

614 if (OldConditional) {

615 OutermostConditional = OldConditional;

616 Builder.restoreIP(OldIP);

617 }

618 break;

619 }

620

621 default:

622 break;

623 }

625 }

627

628

629

630

632 switch (Adjustment.Kind) {

636 Adjustment.DerivedToBase.BasePath->path_begin(),

637 Adjustment.DerivedToBase.BasePath->path_end(),

638 false, E->getExprLoc());

639 break;

640

645 "materialized temporary field is not a simple lvalue");

647 break;

648 }

649

651 llvm::Value *Ptr = EmitScalarExpr(Adjustment.Ptr.RHS);

653 Adjustment.Ptr.MPT);

654 break;

655 }

656 }

657 }

658

660}

661

664

668

670

671

672

673

674

677 }

678

680}

681

682

683

684

686 const llvm::Constant *Elts) {

687 return castllvm::ConstantInt(Elts->getAggregateElement(Idx))

688 ->getZExtValue();

689}

690

692 llvm::Value *Ptr) {

693 llvm::Value *A0 =

694 Builder.CreateMul(Ptr, Builder.getInt64(0xbf58476d1ce4e5b9u));

695 llvm::Value *A1 =

696 Builder.CreateXor(A0, Builder.CreateLShr(A0, Builder.getInt64(31)));

697 return Builder.CreateXor(Acc, A1);

698}

699

703}

704

711}

712

714 return SanOpts.has(SanitizerKind::Null) ||

715 SanOpts.has(SanitizerKind::Alignment) ||

716 SanOpts.has(SanitizerKind::ObjectSize) ||

718}

719

721 llvm::Value *Ptr, QualType Ty,

724 llvm::Value *ArraySize) {

726 return;

727

728

729

730

731 if (Ptr->getType()->getPointerAddressSpace())

732 return;

733

734

735

737 return;

738

739 SanitizerScope SanScope(this);

740

742 Checks;

743 llvm::BasicBlock *Done = nullptr;

744

745

746

747

748 auto PtrToAlloca = dyn_castllvm::AllocaInst(Ptr->stripPointerCasts());

749

751 llvm::Value *IsNonNull = nullptr;

752 bool IsGuaranteedNonNull =

753 SkippedChecks.has(SanitizerKind::Null) || PtrToAlloca;

755 if ((SanOpts.has(SanitizerKind::Null) || AllowNullPointers) &&

756 !IsGuaranteedNonNull) {

757

759

760

761

763

764

765 if (!IsGuaranteedNonNull) {

766 if (AllowNullPointers) {

767

768

771 Builder.CreateCondBr(IsNonNull, Rest, Done);

773 } else {

774 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::SO_Null));

775 }

776 }

777 }

778

779 if (SanOpts.has(SanitizerKind::ObjectSize) &&

780 !SkippedChecks.has(SanitizerKind::ObjectSize) &&

783 llvm::Value *Size = llvm::ConstantInt::get(IntPtrTy, TySize);

784 if (ArraySize)

785 Size = Builder.CreateMul(Size, ArraySize);

786

787

788 llvm::Constant *ConstantSize = dyn_castllvm::Constant(Size);

789 if (!ConstantSize || !ConstantSize->isNullValue()) {

790

791

792

793

795 llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::objectsize, Tys);

796 llvm::Value *Min = Builder.getFalse();

797 llvm::Value *NullIsUnknown = Builder.getFalse();

799 llvm::Value *LargeEnough = Builder.CreateICmpUGE(

800 Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic}), Size);

801 Checks.push_back(

802 std::make_pair(LargeEnough, SanitizerKind::SO_ObjectSize));

803 }

804 }

805

806 llvm::MaybeAlign AlignVal;

807 llvm::Value *PtrAsInt = nullptr;

808

809 if (SanOpts.has(SanitizerKind::Alignment) &&

810 !SkippedChecks.has(SanitizerKind::Alignment)) {

814 true)

816

817

818 if (AlignVal && *AlignVal > llvm::Align(1) &&

819 (!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {

821 llvm::Value *Align = Builder.CreateAnd(

822 PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal->value() - 1));

823 llvm::Value *Aligned =

824 Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));

825 if (Aligned != True)

826 Checks.push_back(std::make_pair(Aligned, SanitizerKind::SO_Alignment));

827 }

828 }

829

830 if (Checks.size() > 0) {

831 llvm::Constant *StaticData[] = {

833 llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),

834 llvm::ConstantInt::get(Int8Ty, TCK)};

835 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,

836 PtrAsInt ? PtrAsInt : Ptr);

837 }

838

839

840

841

842

843

844

845

846

847 if (SanOpts.has(SanitizerKind::Vptr) &&

849

850

851 if (!IsGuaranteedNonNull) {

852 if (!IsNonNull)

854 if (!Done)

856 llvm::BasicBlock *VptrNotNull = createBasicBlock("vptr.not.null");

857 Builder.CreateCondBr(IsNonNull, VptrNotNull, Done);

859 }

860

861

863 llvm::raw_svector_ostream Out(MangledName);

865 Out);

866

867

869 Out.str())) {

870

871 llvm::Value *TypeHash =

872 llvm::ConstantInt::get(Int64Ty, xxh3_64bits(Out.str()));

873

874 llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);

876 llvm::Value *VPtrVal = GetVTablePtr(VPtrAddr, VPtrTy,

879 VPtrVal = Builder.CreateBitOrPointerCast(VPtrVal, IntPtrTy);

880

881 llvm::Value *Hash =

884

885

886 const int CacheSize = 128;

887 llvm::Type *HashTable = llvm::ArrayType::get(IntPtrTy, CacheSize);

889 "__ubsan_vptr_type_cache");

890 llvm::Value *Slot = Builder.CreateAnd(Hash,

891 llvm::ConstantInt::get(IntPtrTy,

892 CacheSize-1));

893 llvm::Value *Indices[] = { Builder.getInt32(0), Slot };

897

898

899

900

901

902 llvm::Value *EqualHash = Builder.CreateICmpEQ(CacheVal, Hash);

903 llvm::Constant *StaticData[] = {

907 llvm::ConstantInt::get(Int8Ty, TCK)

908 };

909 llvm::Value *DynamicData[] = { Ptr, Hash };

910 EmitCheck(std::make_pair(EqualHash, SanitizerKind::SO_Vptr),

911 SanitizerHandler::DynamicTypeCacheMiss, StaticData,

912 DynamicData);

913 }

914 }

915

916 if (Done) {

919 }

920}

921

925 uint64_t EltSize = C.getTypeSizeInChars(EltTy).getQuantity();

926 if (!EltSize)

927 return nullptr;

928

930 if (!ArrayDeclRef)

931 return nullptr;

932

933 auto *ParamDecl = dyn_cast(ArrayDeclRef->getDecl());

934 if (!ParamDecl)

935 return nullptr;

936

937 auto *POSAttr = ParamDecl->getAttr();

938 if (!POSAttr)

939 return nullptr;

940

941

942 int POSType = POSAttr->getType();

943 if (POSType != 0 && POSType != 1)

944 return nullptr;

945

946

947 auto PassedSizeIt = SizeArguments.find(ParamDecl);

948 if (PassedSizeIt == SizeArguments.end())

949 return nullptr;

950

952 assert(LocalDeclMap.count(PassedSizeDecl) && "Passed size not loadable");

953 Address AddrOfSize = LocalDeclMap.find(PassedSizeDecl)->second;

954 llvm::Value *SizeInBytes = EmitLoadOfScalar(AddrOfSize, false,

956 llvm::Value *SizeOfElement =

957 llvm::ConstantInt::get(SizeInBytes->getType(), EltSize);

958 return Builder.CreateUDiv(SizeInBytes, SizeOfElement);

959}

960

961

962

967 StrictFlexArraysLevel) {

968

970 IndexedType = Base->getType();

971 return CGF.Builder.getInt32(VT->getNumElements());

972 }

973

975

976 if (const auto *CE = dyn_cast(Base)) {

977 if (CE->getCastKind() == CK_ArrayToPointerDecay &&

978 !CE->getSubExpr()->isFlexibleArrayMemberLike(CGF.getContext(),

979 StrictFlexArraysLevel)) {

980 CodeGenFunction::SanitizerScope SanScope(&CGF);

981

982 IndexedType = CE->getSubExpr()->getType();

984 if (const auto *CAT = dyn_cast(AT))

985 return CGF.Builder.getInt(CAT->getSize());

986

987 if (const auto *VAT = dyn_cast(AT))

989

990 }

991 }

992

993 CodeGenFunction::SanitizerScope SanScope(&CGF);

994

995 QualType EltTy{Base->getType()->getPointeeOrArrayElementType(), 0};

997 IndexedType = Base->getType();

998 return POS;

999 }

1000

1001 return nullptr;

1002}

1003

1004namespace {

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022class StructAccessBase

1025

1026 bool IsExpectedRecordDecl(const Expr *E) const {

1031 }

1032

1033public:

1034 StructAccessBase(const RecordDecl *ExpectedRD) : ExpectedRD(ExpectedRD) {}

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053 const Expr *Visit(const Expr *E) {

1055 }

1056

1057 const Expr *VisitStmt(const Stmt *S) { return nullptr; }

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1073 return IsExpectedRecordDecl(E) ? E : nullptr;

1074 }

1076 if (IsExpectedRecordDecl(E) && E->isArrow())

1077 return E;

1078 const Expr *Res = Visit(E->getBase());

1079 return !Res && IsExpectedRecordDecl(E) ? E : Res;

1080 }

1082 return IsExpectedRecordDecl(E) ? E : nullptr;

1083 }

1085 return IsExpectedRecordDecl(E) ? E : nullptr;

1086 }

1087

1089 if (IsExpectedRecordDecl(E))

1090 return E;

1091 return Visit(E->getBase());

1092 }

1094 if (E->getCastKind() == CK_LValueToRValue)

1095 return IsExpectedRecordDecl(E) ? E : nullptr;

1096 return Visit(E->getSubExpr());

1097 }

1099 return Visit(E->getSubExpr());

1100 }

1102 return Visit(E->getSubExpr());

1103 }

1105 return Visit(E->getSubExpr());

1106 }

1107};

1108

1109}

1110

1112

1117 int64_t FieldNo = -1;

1120

1121

1122 continue;

1123

1125 if (FD == Field) {

1126 Indices.emplace_back(CGF.Builder.getInt32(FieldNo));

1127 return true;

1128 }

1129

1130 QualType Ty = FD->getType();

1134 FieldNo = 0;

1135 Indices.emplace_back(CGF.Builder.getInt32(FieldNo));

1136 return true;

1137 }

1138 }

1139 }

1140

1141 return false;

1142}

1143

1147

1148

1149 const Expr *StructBase = StructAccessBase(RD).Visit(Base);

1151 return nullptr;

1152

1153 llvm::Value *Res = nullptr;

1159 } else if (StructBase->isLValue()) {

1163 } else {

1164 return nullptr;

1165 }

1166

1169 if (Indices.empty())

1170 return nullptr;

1171

1172 Indices.push_back(Builder.getInt32(0));

1175 RecIndicesTy(llvm::reverse(Indices)), "counted_by.gep");

1176}

1177

1178

1179

1180

1181

1182

1183

1184

1185

1191 return nullptr;

1192}

1193

1195 llvm::Value *Index, QualType IndexType,

1196 bool Accessed) {

1197 assert(SanOpts.has(SanitizerKind::ArrayBounds) &&

1198 "should not be called unless adding bounds checks");

1200 getLangOpts().getStrictFlexArraysLevel();

1202 llvm::Value *Bound =

1204

1206}

1207

1209 llvm::Value *Index,

1211 QualType IndexedType, bool Accessed) {

1212 if (!Bound)

1213 return;

1214

1215 SanitizerScope SanScope(this);

1216

1218 llvm::Value *IndexVal = Builder.CreateIntCast(Index, SizeTy, IndexSigned);

1219 llvm::Value *BoundVal = Builder.CreateIntCast(Bound, SizeTy, false);

1220

1221 llvm::Constant *StaticData[] = {

1225 };

1226 llvm::Value *Check = Accessed ? Builder.CreateICmpULT(IndexVal, BoundVal)

1227 : Builder.CreateICmpULE(IndexVal, BoundVal);

1228 EmitCheck(std::make_pair(Check, SanitizerKind::SO_ArrayBounds),

1229 SanitizerHandler::OutOfBounds, StaticData, Index);

1230}

1231

1234 bool isInc, bool isPre) {

1236

1237 llvm::Value *NextVal;

1238 if (isallvm::IntegerType(InVal.first->getType())) {

1239 uint64_t AmountVal = isInc ? 1 : -1;

1240 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal, true);

1241

1242

1243 NextVal = Builder.CreateAdd(InVal.first, NextVal, isInc ? "inc" : "dec");

1244 } else {

1246 llvm::APFloat FVal(getContext().getFloatTypeSemantics(ElemTy), 1);

1247 if (!isInc)

1248 FVal.changeSign();

1249 NextVal = llvm::ConstantFP::get(getLLVMContext(), FVal);

1250

1251

1252 NextVal = Builder.CreateFAdd(InVal.first, NextVal, isInc ? "inc" : "dec");

1253 }

1254

1256

1257

1261 E->getSubExpr());

1262

1263

1264

1265 return isPre ? IncVal : InVal;

1266}

1267

1270

1273

1275 DI->EmitExplicitCastType(E->getType());

1276}

1277

1278

1279

1280

1281

1286

1290

1291

1292 if (const CastExpr *CE = dyn_cast(E)) {

1293 if (const auto *ECE = dyn_cast(CE))

1295

1296 switch (CE->getCastKind()) {

1297

1298 case CK_BitCast:

1299 case CK_NoOp:

1300 case CK_AddressSpaceConversion:

1301 if (auto PtrTy = CE->getSubExpr()->getType()->getAs<PointerType>()) {

1302 if (PtrTy->getPointeeType()->isVoidType())

1303 break;

1304

1308 CE->getSubExpr(), &InnerBaseInfo, &InnerTBAAInfo, IsKnownNonNull);

1309 if (BaseInfo) *BaseInfo = InnerBaseInfo;

1310 if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;

1311

1312 if (isa(CE)) {

1316 E->getType(), &TargetTypeBaseInfo, &TargetTypeTBAAInfo);

1317 if (TBAAInfo)

1318 *TBAAInfo =

1320

1321

1323 if (BaseInfo)

1326 }

1327 }

1328

1329 if (CGF.SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&

1330 CE->getCastKind() == CK_BitCast) {

1333 true,

1335 CE->getBeginLoc());

1336 }

1337

1338 llvm::Type *ElemTy =

1341 if (CE->getCastKind() == CK_AddressSpaceConversion)

1345 CE->getType());

1346 }

1347 break;

1348

1349

1350 case CK_ArrayToPointerDecay:

1352

1353

1354 case CK_UncheckedDerivedToBase:

1355 case CK_DerivedToBase: {

1356

1357

1358

1359 if (TBAAInfo)

1362 CE->getSubExpr(), BaseInfo, nullptr,

1364 CE->getCastKind() == CK_UncheckedDerivedToBase));

1365 auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();

1367 Addr, Derived, CE->path_begin(), CE->path_end(),

1369 }

1370

1371

1372

1373 default:

1374 break;

1375 }

1376 }

1377

1378

1379 if (const UnaryOperator *UO = dyn_cast(E)) {

1380 if (UO->getOpcode() == UO_AddrOf) {

1381 LValue LV = CGF.EmitLValue(UO->getSubExpr(), IsKnownNonNull);

1382 if (BaseInfo) *BaseInfo = LV.getBaseInfo();

1383 if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();

1385 }

1386 }

1387

1388

1389 if (auto *Call = dyn_cast(E)) {

1390 switch (Call->getBuiltinCallee()) {

1391 default:

1392 break;

1393 case Builtin::BIaddressof:

1394 case Builtin::BI__addressof:

1395 case Builtin::BI__builtin_addressof: {

1397 if (BaseInfo) *BaseInfo = LV.getBaseInfo();

1398 if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();

1400 }

1401 }

1402 }

1403

1404

1405

1406

1409 true, BaseInfo, TBAAInfo, IsKnownNonNull);

1410}

1411

1412

1413

1421 return Addr;

1422}

1423

1428 return Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));

1429}

1430

1434

1437 llvm::Type *EltTy =

1439 llvm::Value *U = llvm::UndefValue::get(EltTy);

1441 }

1442

1443

1444

1445

1449 }

1450

1453 }

1454 llvm_unreachable("bad evaluation kind");

1455}

1456

1458 const char *Name) {

1461}

1462

1464 const char *Name) {

1470}

1471

1474 while (!isa(Base)) {

1475

1476 if (isa(Base))

1477 return false;

1478

1479 if (const auto *CE = dyn_cast(Base)) {

1480 Base = CE->getSubExpr();

1481 } else if (const auto *PE = dyn_cast(Base)) {

1482 Base = PE->getSubExpr();

1483 } else if (const auto *UO = dyn_cast(Base)) {

1484 if (UO->getOpcode() == UO_Extension)

1485 Base = UO->getSubExpr();

1486 else

1487 return false;

1488 } else {

1489 return false;

1490 }

1491 }

1492 return true;

1493}

1494

1497 if (SanOpts.has(SanitizerKind::ArrayBounds) && isa(E))

1499 else

1503 if (const auto *ME = dyn_cast(E)) {

1505 if (IsBaseCXXThis)

1506 SkippedChecks.set(SanitizerKind::Alignment, true);

1507 if (IsBaseCXXThis || isa(ME->getBase()))

1508 SkippedChecks.set(SanitizerKind::Null, true);

1509 }

1511 }

1512 return LV;

1513}

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1532

1533

1536 E->getExprLoc(), [&] { LV = EmitLValueHelper(E, IsKnownNonNull); });

1537

1540 return LV;

1541}

1542

1546 if (isa(SE))

1548 return cast(SE)->getCallReturnType(Ctx)->getPointeeType();

1549}

1550

1551LValue CodeGenFunction::EmitLValueHelper(const Expr *E,

1556

1557 case Expr::ObjCPropertyRefExprClass:

1558 llvm_unreachable("cannot emit a property reference directly");

1559

1560 case Expr::ObjCSelectorExprClass:

1562 case Expr::ObjCIsaExprClass:

1564 case Expr::BinaryOperatorClass:

1566 case Expr::CompoundAssignOperatorClass: {

1569 Ty = AT->getValueType();

1573 }

1574 case Expr::CallExprClass:

1575 case Expr::CXXMemberCallExprClass:

1576 case Expr::CXXOperatorCallExprClass:

1577 case Expr::UserDefinedLiteralClass:

1579 case Expr::CXXRewrittenBinaryOperatorClass:

1580 return EmitLValue(cast(E)->getSemanticForm(),

1581 IsKnownNonNull);

1582 case Expr::VAArgExprClass:

1584 case Expr::DeclRefExprClass:

1586 case Expr::ConstantExprClass: {

1591 }

1592 return EmitLValue(cast(E)->getSubExpr(), IsKnownNonNull);

1593 }

1594 case Expr::ParenExprClass:

1595 return EmitLValue(cast(E)->getSubExpr(), IsKnownNonNull);

1596 case Expr::GenericSelectionExprClass:

1597 return EmitLValue(cast(E)->getResultExpr(),

1598 IsKnownNonNull);

1599 case Expr::PredefinedExprClass:

1601 case Expr::StringLiteralClass:

1603 case Expr::ObjCEncodeExprClass:

1605 case Expr::PseudoObjectExprClass:

1607 case Expr::InitListExprClass:

1609 case Expr::CXXTemporaryObjectExprClass:

1610 case Expr::CXXConstructExprClass:

1612 case Expr::CXXBindTemporaryExprClass:

1614 case Expr::CXXUuidofExprClass:

1616 case Expr::LambdaExprClass:

1618

1619 case Expr::ExprWithCleanupsClass: {

1620 const auto *cleanups = cast(E);

1621 RunCleanupsScope Scope(*this);

1622 LValue LV = EmitLValue(cleanups->getSubExpr(), IsKnownNonNull);

1624

1625

1628 Scope.ForceCleanup({&V});

1632 }

1633

1634

1635 return LV;

1636 }

1637

1638 case Expr::CXXDefaultArgExprClass: {

1639 auto *DAE = cast(E);

1640 CXXDefaultArgExprScope Scope(*this, DAE);

1641 return EmitLValue(DAE->getExpr(), IsKnownNonNull);

1642 }

1643 case Expr::CXXDefaultInitExprClass: {

1644 auto *DIE = cast(E);

1645 CXXDefaultInitExprScope Scope(*this, DIE);

1646 return EmitLValue(DIE->getExpr(), IsKnownNonNull);

1647 }

1648 case Expr::CXXTypeidExprClass:

1650

1651 case Expr::ObjCMessageExprClass:

1653 case Expr::ObjCIvarRefExprClass:

1655 case Expr::StmtExprClass:

1657 case Expr::UnaryOperatorClass:

1659 case Expr::ArraySubscriptExprClass:

1661 case Expr::MatrixSubscriptExprClass:

1663 case Expr::ArraySectionExprClass:

1665 case Expr::ExtVectorElementExprClass:

1667 case Expr::CXXThisExprClass:

1669 case Expr::MemberExprClass:

1671 case Expr::CompoundLiteralExprClass:

1673 case Expr::ConditionalOperatorClass:

1675 case Expr::BinaryConditionalOperatorClass:

1677 case Expr::ChooseExprClass:

1678 return EmitLValue(cast(E)->getChosenSubExpr(), IsKnownNonNull);

1679 case Expr::OpaqueValueExprClass:

1681 case Expr::SubstNonTypeTemplateParmExprClass:

1682 return EmitLValue(cast(E)->getReplacement(),

1683 IsKnownNonNull);

1684 case Expr::ImplicitCastExprClass:

1685 case Expr::CStyleCastExprClass:

1686 case Expr::CXXFunctionalCastExprClass:

1687 case Expr::CXXStaticCastExprClass:

1688 case Expr::CXXDynamicCastExprClass:

1689 case Expr::CXXReinterpretCastExprClass:

1690 case Expr::CXXConstCastExprClass:

1691 case Expr::CXXAddrspaceCastExprClass:

1692 case Expr::ObjCBridgedCastExprClass:

1694

1695 case Expr::MaterializeTemporaryExprClass:

1697

1698 case Expr::CoawaitExprClass:

1700 case Expr::CoyieldExprClass:

1702 case Expr::PackIndexingExprClass:

1703 return EmitLValue(cast(E)->getSelectedExpr());

1704 case Expr::HLSLOutArgExprClass:

1705 llvm_unreachable("cannot emit a HLSL out argument directly");

1706 }

1707}

1708

1709

1710

1712 assert(type.isCanonical());

1713 assert(type->isReferenceType());

1714

1715

1718

1719

1720

1721 if (const auto *RT = dyn_cast(type))

1722 if (const auto *RD = dyn_cast(RT->getDecl()))

1723 if (RD->hasMutableFields() || !RD->isTrivial())

1724 return false;

1725

1726 return true;

1727}

1728

1729

1730

1731

1732

1733

1734

1735

1743 type = type.getCanonicalType();

1744 if (const auto *ref = dyn_cast(type)) {

1748 }

1752}

1753

1754

1755

1756

1757

1758

1759

1760CodeGenFunction::ConstantEmission

1763

1764

1766 if (isa(value)) {

1768 } else if (auto *var = dyn_cast(value)) {

1770 } else if (isa(value)) {

1772 } else {

1774 }

1775 if (CEK == CEK_None) return ConstantEmission();

1776

1778 bool resultIsReference;

1780

1781

1784 resultIsReference = false;

1785 resultType = refExpr->getType();

1786

1787

1790 resultIsReference = true;

1791 resultType = value->getType();

1792

1793

1794 } else {

1795 return ConstantEmission();

1796 }

1797

1798

1800 return ConstantEmission();

1801

1802

1803

1804

1805

1806

1807

1808

1811 auto *MD = dyn_cast_or_null(CurCodeDecl);

1812 if (MD && MD->getParent()->isLambda() &&

1813 MD->getOverloadedOperator() == OO_Call) {

1816 if (const VarDecl *VD = dyn_cast(D)) {

1817 if (!VD->hasAttr()) {

1818 return ConstantEmission();

1819 }

1820 }

1821 }

1822 }

1823 }

1824

1825

1827 result.Val, resultType);

1828

1829

1830

1831 if (isa(value)) {

1832 if (getContext().DeclMustBeEmitted(cast(value)))

1834 } else {

1835 assert(isa(value));

1837 }

1838

1839

1840 if (resultIsReference)

1842

1844}

1845

1848 if (auto *VD = dyn_cast(ME->getMemberDecl())) {

1849

1852 false, ME->getExprLoc(),

1854 }

1855 return nullptr;

1856}

1857

1858CodeGenFunction::ConstantEmission

1862 return ConstantEmission();

1863}

1864

1866 const CodeGenFunction::ConstantEmission &Constant, Expr *E) {

1867 assert(Constant && "not a constant");

1868 if (Constant.isReference())

1872 return Constant.getValue();

1873}

1874

1880}

1881

1884 return true;

1885

1887 return ET->getDecl()->getIntegerType()->isBooleanType();

1888

1891

1892 return false;

1893}

1894

1896 llvm::APInt &Min, llvm::APInt &End,

1897 bool StrictEnums, bool IsBool) {

1899 bool IsRegularCPlusPlusEnum = CGF.getLangOpts().CPlusPlus && StrictEnums &&

1901 if (!IsBool && !IsRegularCPlusPlusEnum)

1902 return false;

1903

1904 if (IsBool) {

1907 } else {

1910 }

1911 return true;

1912}

1913

1914llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(QualType Ty) {

1915 llvm::APInt Min, End;

1918 return nullptr;

1919

1921 return MDHelper.createRange(Min, End);

1922}

1923

1926 bool HasBoolCheck = SanOpts.has(SanitizerKind::Bool);

1927 bool HasEnumCheck = SanOpts.has(SanitizerKind::Enum);

1928 if (!HasBoolCheck && !HasEnumCheck)

1929 return false;

1930

1933 bool NeedsBoolCheck = HasBoolCheck && IsBool;

1934 bool NeedsEnumCheck = HasEnumCheck && Ty->getAs<EnumType>();

1935 if (!NeedsBoolCheck && !NeedsEnumCheck)

1936 return false;

1937

1938

1939

1940

1941 if (IsBool &&

1942 castllvm::IntegerType(Value->getType())->getBitWidth() == 1)

1943 return false;

1944

1945 if (NeedsEnumCheck &&

1947 return false;

1948

1949 llvm::APInt Min, End;

1950 if (getRangeForType(*this, Ty, Min, End, true, IsBool))

1951 return true;

1952

1954 SanitizerScope SanScope(this);

1955 llvm::Value *Check;

1956 --End;

1957 if (Min) {

1958 Check = Builder.CreateICmpULE(Value, llvm::ConstantInt::get(Ctx, End));

1959 } else {

1960 llvm::Value *Upper =

1961 Builder.CreateICmpSLE(Value, llvm::ConstantInt::get(Ctx, End));

1962 llvm::Value *Lower =

1963 Builder.CreateICmpSGE(Value, llvm::ConstantInt::get(Ctx, Min));

1964 Check = Builder.CreateAnd(Upper, Lower);

1965 }

1969 NeedsEnumCheck ? SanitizerKind::SO_Enum : SanitizerKind::SO_Bool;

1970 EmitCheck(std::make_pair(Check, Kind), SanitizerHandler::LoadInvalidValue,

1972 return true;

1973}

1974

1980 bool isNontemporal) {

1981 if (auto *GV = dyn_castllvm::GlobalValue(Addr.getBasePointer()))

1982 if (GV->isThreadLocal())

1985

1987

1988 if (ClangVecTy->isExtVectorBoolType()) {

1990 unsigned ValNumElems =

1991 castllvm::FixedVectorType(ValTy)->getNumElements();

1992

1993 auto *RawIntV = Builder.CreateLoad(Addr, Volatile, "load_bits");

1994 const auto *RawIntTy = RawIntV->getType();

1995 assert(RawIntTy->isIntegerTy() && "compressed iN storage for bitvectors");

1996

1997 auto *PaddedVecTy = llvm::FixedVectorType::get(

1998 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());

1999 llvm::Value *V = Builder.CreateBitCast(RawIntV, PaddedVecTy);

2000

2002

2004 }

2005

2006

2007

2008 auto *VTy = castllvm::FixedVectorType(Addr.getElementType());

2009 auto *NewVecTy =

2011

2012 if (VTy != NewVecTy) {

2015 unsigned OldNumElements = VTy->getNumElements();

2017 std::iota(Mask.begin(), Mask.end(), 0);

2018 V = Builder.CreateShuffleVector(V, Mask, "extractVec");

2020 }

2021 }

2022

2023

2024 LValue AtomicLValue =

2028 }

2029

2030 Addr =

2032

2034 if (isNontemporal) {

2035 llvm::MDNode *Node = llvm::MDNode::get(

2036 Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));

2037 Load->setMetadata(llvm::LLVMContext::MD_nontemporal, Node);

2038 }

2039

2041

2043

2044

2046 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) {

2047 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);

2048 Load->setMetadata(llvm::LLVMContext::MD_noundef,

2050 }

2051

2053}

2054

2055

2056

2057

2063 }

2064

2067

2068 unsigned MemNumElems = StoreTy->getPrimitiveSizeInBits();

2069

2071

2073 }

2074

2076}

2077

2078

2079

2080

2084

2085 auto *PaddedVecTy = llvm::FixedVectorType::get(

2086 Builder.getInt1Ty(), RawIntTy->getPrimitiveSizeInBits());

2087 auto *V = Builder.CreateBitCast(Value, PaddedVecTy);

2088

2090 unsigned ValNumElems = castllvm::FixedVectorType(ValTy)->getNumElements();

2092 }

2093

2096 return Builder.CreateTrunc(Value, ResTy, "loadedv");

2097 }

2098

2100}

2101

2102

2103

2106 bool IsVector = true) {

2107 auto *ArrayTy = dyn_castllvm::ArrayType(Addr.getElementType());

2108 if (ArrayTy && IsVector) {

2109 auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(),

2110 ArrayTy->getNumElements());

2111

2113 }

2114 auto *VectorTy = dyn_castllvm::VectorType(Addr.getElementType());

2115 if (VectorTy && !IsVector) {

2116 auto *ArrayTy = llvm::ArrayType::get(

2117 VectorTy->getElementType(),

2118 castllvm::FixedVectorType(VectorTy)->getNumElements());

2119

2121 }

2122

2123 return Addr;

2124}

2125

2126

2127

2128

2132 value->getType()->isVectorTy());

2136}

2137

2142 bool isInit, bool isNontemporal) {

2143 if (auto *GV = dyn_castllvm::GlobalValue(Addr.getBasePointer()))

2144 if (GV->isThreadLocal())

2147

2148

2149

2152 if (auto *VecTy = dyn_castllvm::FixedVectorType(SrcTy)) {

2153 auto *NewVecTy =

2155 if (!ClangVecTy->isExtVectorBoolType() && VecTy != NewVecTy) {

2157 std::iota(Mask.begin(), Mask.begin() + VecTy->getNumElements(), 0);

2159 SrcTy = NewVecTy;

2160 }

2163 }

2164 }

2165

2167

2168 LValue AtomicLValue =

2173 return;

2174 }

2175

2177 if (isNontemporal) {

2178 llvm::MDNode *Node =

2179 llvm::MDNode::get(Store->getContext(),

2180 llvm::ConstantAsMetadata::get(Builder.getInt32(1)));

2181 Store->setMetadata(llvm::LLVMContext::MD_nontemporal, Node);

2182 }

2183

2185}

2186

2188 bool isInit) {

2191 return;

2192 }

2193

2197}

2198

2199

2200

2207}

2208

2220 }

2221 llvm_unreachable("bad evaluation kind");

2222}

2223

2224

2225

2226

2229

2232 AddrWeakObj));

2233 }

2235

2238 }

2239

2240

2244 }

2245

2248

2251

2252

2254 }

2255

2260 "vecext"));

2261 }

2262

2263

2264

2267 }

2268

2269

2272

2277 llvm::MatrixBuilder MB(Builder);

2278 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());

2279 }

2280 llvm::LoadInst *Load =

2282 return RValue::get(Builder.CreateExtractElement(Load, Idx, "matrixext"));

2283 }

2284

2285 assert(LV.isBitField() && "Unknown LValue type!");

2287}

2288

2292

2293

2295

2297 llvm::Value *Val =

2299

2303 const unsigned StorageSize =

2306 assert(static_cast<unsigned>(Offset + Info.Size) <= StorageSize);

2307 unsigned HighBits = StorageSize - Offset - Info.Size;

2308 if (HighBits)

2309 Val = Builder.CreateShl(Val, HighBits, "bf.shl");

2310 if (Offset + HighBits)

2311 Val = Builder.CreateAShr(Val, Offset + HighBits, "bf.ashr");

2312 } else {

2313 if (Offset)

2314 Val = Builder.CreateLShr(Val, Offset, "bf.lshr");

2315 if (static_cast<unsigned>(Offset) + Info.Size < StorageSize)

2316 Val = Builder.CreateAnd(

2317 Val, llvm::APInt::getLowBitsSet(StorageSize, Info.Size), "bf.clear");

2318 }

2319 Val = Builder.CreateIntCast(Val, ResLTy, Info.IsSigned, "bf.cast");

2322}

2323

2324

2325

2329

2330

2331

2332 if (getLangOpts().HLSL && !Vec->getType()->isVectorTy()) {

2333 llvm::Type *DstTy = llvm::FixedVectorType::get(Vec->getType(), 1);

2334 llvm::Value *Zero = llvm::Constant::getNullValue(CGM.Int64Ty);

2335 Vec = Builder.CreateInsertElement(DstTy, Vec, Zero, "cast.splat");

2336 }

2337

2339

2340

2341

2343 if (!ExprVT) {

2345 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);

2347 }

2348

2349

2351

2353 for (unsigned i = 0; i != NumResultElts; ++i)

2355

2356 Vec = Builder.CreateShuffleVector(Vec, Mask);

2358}

2359

2360

2365

2367

2370

2371 Address VectorBasePtrPlusIx =

2373 "vector.elt");

2374

2375 return VectorBasePtrPlusIx;

2376}

2377

2378

2381 "Bad type for register variable");

2382 llvm::MDNode *RegName = castllvm::MDNode(

2383 castllvm::MetadataAsValue(LV.getGlobalReg())->getMetadata());

2384

2385

2387 llvm::Type *Ty = OrigTy;

2388 if (OrigTy->isPointerTy())

2390 llvm::Type *Types[] = { Ty };

2391

2392 llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types);

2394 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));

2395 if (OrigTy->isPointerTy())

2398}

2399

2400

2401

2402

2404 bool isInit) {

2407

2410 auto *IRStoreTy = dyn_castllvm::IntegerType(Vec->getType());

2411 if (IRStoreTy) {

2412 auto *IRVecTy = llvm::FixedVectorType::get(

2413 Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());

2414 Vec = Builder.CreateBitCast(Vec, IRVecTy);

2415

2416 }

2419 if (IRStoreTy) {

2420

2421 Vec = Builder.CreateBitCast(Vec, IRStoreTy);

2422 }

2425 return;

2426 }

2427

2428

2429

2432

2435

2440 llvm::MatrixBuilder MB(Builder);

2441 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());

2442 }

2444 llvm::Value *Vec =

2448 return;

2449 }

2450

2451 assert(Dst.isBitField() && "Unknown LValue type");

2453 }

2454

2455

2457 switch (Lifetime) {

2459 llvm_unreachable("present but none");

2460

2462

2463 break;

2464

2466 if (isInit) {

2468 break;

2469 }

2471 return;

2472

2474 if (isInit)

2475

2477 else

2479 true);

2480 return;

2481

2485

2486 break;

2487 }

2488 }

2489

2491

2495 return;

2496 }

2497

2499

2503 assert(Dst.getBaseIvarExp() && "BaseIvarExp is NULL");

2504 llvm::Type *ResultType = IntPtrTy;

2507 RHS = Builder.CreatePtrToInt(RHS, ResultType, "sub.ptr.rhs.cast");

2509 ResultType, "sub.ptr.lhs.cast");

2510 llvm::Value *BytesBetween = Builder.CreateSub(LHS, RHS, "ivar.offset");

2515 }

2516 else

2518 return;

2519 }

2520

2521 assert(Src.isScalar() && "Can't emit an agg store with this method");

2523}

2524

2526 llvm::Value **Result) {

2530

2531

2533

2534

2536 false);

2537 llvm::Value *MaskedVal = SrcVal;

2538

2539 const bool UseVolatile =

2542 const unsigned StorageSize =

2545

2546

2547 if (StorageSize != Info.Size) {

2548 assert(StorageSize > Info.Size && "Invalid bitfield size.");

2549 llvm::Value *Val =

2551

2552

2554 SrcVal = Builder.CreateAnd(

2555 SrcVal, llvm::APInt::getLowBitsSet(StorageSize, Info.Size),

2556 "bf.value");

2557 MaskedVal = SrcVal;

2558 if (Offset)

2559 SrcVal = Builder.CreateShl(SrcVal, Offset, "bf.shl");

2560

2561

2562 Val = Builder.CreateAnd(

2563 Val, ~llvm::APInt::getBitsSet(StorageSize, Offset, Offset + Info.Size),

2564 "bf.clear");

2565

2566

2567 SrcVal = Builder.CreateOr(Val, SrcVal, "bf.set");

2568 } else {

2569 assert(Offset == 0);

2570

2571

2572

2573

2574

2578 }

2579

2580

2582

2583

2585 llvm::Value *ResultVal = MaskedVal;

2586

2587

2589 assert(Info.Size <= StorageSize);

2590 unsigned HighBits = StorageSize - Info.Size;

2591 if (HighBits) {

2592 ResultVal = Builder.CreateShl(ResultVal, HighBits, "bf.result.shl");

2593 ResultVal = Builder.CreateAShr(ResultVal, HighBits, "bf.result.ashr");

2594 }

2595 }

2596

2597 ResultVal = Builder.CreateIntCast(ResultVal, ResLTy, Info.IsSigned,

2598 "bf.result.cast");

2600 }

2601}

2602

2605

2606

2607

2611 "this should only occur for non-vector l-values");

2613 return;

2614 }

2615

2616

2617

2620

2622

2624 unsigned NumSrcElts = VTy->getNumElements();

2625 unsigned NumDstElts =

2626 castllvm::FixedVectorType(Vec->getType())->getNumElements();

2627 if (NumDstElts == NumSrcElts) {

2628

2629

2630

2632 for (unsigned i = 0; i != NumSrcElts; ++i)

2634

2635 Vec = Builder.CreateShuffleVector(SrcVal, Mask);

2636 } else if (NumDstElts > NumSrcElts) {

2637

2638

2639

2640

2642 for (unsigned i = 0; i != NumSrcElts; ++i)

2643 ExtMask.push_back(i);

2644 ExtMask.resize(NumDstElts, -1);

2645 llvm::Value *ExtSrcVal = Builder.CreateShuffleVector(SrcVal, ExtMask);

2646

2648 for (unsigned i = 0; i != NumDstElts; ++i)

2649 Mask.push_back(i);

2650

2651

2652

2653

2655 NumSrcElts--;

2656

2657

2658 for (unsigned i = 0; i != NumSrcElts; ++i)

2660 Vec = Builder.CreateShuffleVector(Vec, ExtSrcVal, Mask);

2661 } else {

2662

2663 llvm_unreachable("unexpected shorten vector length");

2664 }

2665 } else {

2666

2667

2669 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);

2670 Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt);

2671 }

2672

2675}

2676

2677

2680 "Bad type for register variable");

2681 llvm::MDNode *RegName = castllvm::MDNode(

2682 castllvm::MetadataAsValue(Dst.getGlobalReg())->getMetadata());

2683 assert(RegName && "Register LValue is not metadata");

2684

2685

2687 llvm::Type *Ty = OrigTy;

2688 if (OrigTy->isPointerTy())

2690 llvm::Type *Types[] = { Ty };

2691

2692 llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types);

2694 if (OrigTy->isPointerTy())

2697 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName), Value});

2698}

2699

2700

2701

2702

2705 bool IsMemberAccess=false) {

2707 return;

2708

2709 if (isa(E)) {

2712

2713

2714

2718 return;

2719 }

2720 }

2722 auto *Exp = cast(const_cast<Expr *>(E));

2725 return;

2726 }

2727

2728 if (const auto *Exp = dyn_cast(E)) {

2729 if (const auto *VD = dyn_cast(Exp->getDecl())) {

2730 if (VD->hasGlobalStorage()) {

2733 }

2734 }

2736 return;

2737 }

2738

2739 if (const auto *Exp = dyn_cast(E)) {

2741 return;

2742 }

2743

2744 if (const auto *Exp = dyn_cast(E)) {

2747

2748

2754 }

2755 return;

2756 }

2757

2758 if (const auto *Exp = dyn_cast(E)) {

2760 return;

2761 }

2762

2763 if (const auto *Exp = dyn_cast(E)) {

2765 return;

2766 }

2767

2768 if (const auto *Exp = dyn_cast(E)) {

2770 return;

2771 }

2772

2773 if (const auto *Exp = dyn_cast(E)) {

2775 return;

2776 }

2777

2778 if (const auto *Exp = dyn_cast(E)) {

2781

2782

2785

2786

2788 return;

2789 }

2790

2791 if (const auto *Exp = dyn_cast(E)) {

2793

2794

2796 return;

2797 }

2798}

2799

2805 CGF, VD, Addr, Loc);

2806 else

2807 Addr =

2809

2812}

2813

2816 std::optionalOMPDeclareTargetDeclAttr::MapTypeTy Res =

2817 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);

2818

2819

2820

2821 if (!Res || ((*Res == OMPDeclareTargetDeclAttr::MT_To ||

2822 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&

2825 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||

2826 ((*Res == OMPDeclareTargetDeclAttr::MT_To ||

2827 *Res == OMPDeclareTargetDeclAttr::MT_Enter) &&

2829 "Expected link clause OR to clause with unified memory enabled.");

2833}

2834

2839 llvm::LoadInst *Load =

2843 CharUnits(), true,

2844 PointeeBaseInfo, PointeeTBAAInfo);

2845}

2846

2851 &PointeeTBAAInfo);

2853 PointeeBaseInfo, PointeeTBAAInfo);

2854}

2855

2862 CharUnits(), true,

2863 BaseInfo, TBAAInfo);

2864}

2865

2872}

2873

2877

2878

2882

2883

2884 if (CGF.getLangOpts().OpenMPIsTargetDevice) {

2888 }

2889

2891

2893 V = CGF.Builder.CreateThreadLocalAddress(V);

2894

2897 Address Addr(V, RealVarTy, Alignment);

2898

2899

2901 VD->hasAttr()) {

2904 }

2910 return LV;

2911}

2912

2914 llvm::Type *Ty) {

2916 if (FD->hasAttr()) {

2919 }

2920

2922 return V;

2923}

2924

2932}

2933

2935 llvm::Value *ThisValue) {

2936

2938}

2939

2940

2941

2942

2943

2944

2945

2948 AsmLabelAttr *Asm = VD->getAttr();

2949 assert(Asm->getLabel().size() < 64-Name.size() &&

2950 "Register name too big");

2951 Name.append(Asm->getLabel());

2952 llvm::NamedMDNode *M =

2953 CGM.getModule().getOrInsertNamedMetadata(Name);

2954 if (M->getNumOperands() == 0) {

2955 llvm::MDString *Str = llvm::MDString::get(CGM.getLLVMContext(),

2956 Asm->getLabel());

2957 llvm::Metadata *Ops[] = {Str};

2958 M->addOperand(llvm::MDNode::get(CGM.getLLVMContext(), Ops));

2959 }

2960

2962

2963 llvm::Value *Ptr =

2964 llvm::MetadataAsValue::get(CGM.getLLVMContext(), M->getOperand(0));

2966}

2967

2968

2969

2970

2974

2975

2976

2977

2978 if (E->refersToEnclosingVariableOrCapture())

2979 return false;

2980

2981

2982

2985 dyn_cast_or_null(CGF.CurCodeDecl);

2986 }

2987

2988

2989

2991 if (!VD)

2992 return false;

2993

2994

2995

2996

2997

3000 return false;

3001 }

3002

3003

3004

3005

3007 case llvm::GlobalValue::ExternalLinkage:

3008 case llvm::GlobalValue::LinkOnceODRLinkage:

3009 case llvm::GlobalValue::WeakODRLinkage:

3010 case llvm::GlobalValue::InternalLinkage:

3011 case llvm::GlobalValue::PrivateLinkage:

3012 return true;

3013 default:

3014 return false;

3015 }

3016}

3017

3021

3023 "should not emit an unevaluated operand");

3024

3025 if (const auto *VD = dyn_cast(ND)) {

3026

3027 if (VD->getStorageClass() == SC_Register &&

3028 VD->hasAttr() && !VD->isLocalVarDecl())

3030

3031

3032

3033

3034

3036 (VD->getType()->isReferenceType() ||

3038 VD->getAnyInitializer(VD);

3040 E->getLocation(), *VD->evaluateValue(), VD->getType());

3041 assert(Val && "failed to emit constant expression");

3042

3044 if (!VD->getType()->isReferenceType()) {

3045

3049 auto *PTy = llvm::PointerType::get(

3050 VarTy, getTypes().getTargetAddressSpace(VD->getType()));

3052 } else {

3053

3056 nullptr,

3057 nullptr,

3058 true);

3060 }

3062 }

3063

3064

3065

3066

3067 if (E->refersToEnclosingVariableOrCapture()) {

3068 VD = VD->getCanonicalDecl();

3072 auto I = LocalDeclMap.find(VD);

3073 if (I != LocalDeclMap.end()) {

3075 if (VD->getType()->isReferenceType())

3078 else

3080

3081

3085 return CapLVal;

3086 }

3097

3098

3102 return CapLVal;

3103 }

3104

3108 }

3109 }

3110

3111

3112

3113

3114 assert((ND->isUsed(false) || !isa(ND) || E->isNonOdrUse() ||

3115 E->getLocation().isValid()) &&

3116 "Should not use decl without marking it used!");

3117

3118 if (ND->hasAttr()) {

3119 const auto *VD = cast(ND);

3122 }

3123

3124 if (const auto *VD = dyn_cast(ND)) {

3125

3126 if (VD->hasLinkage() || VD->isStaticDataMember())

3128

3130

3131

3132 auto iter = LocalDeclMap.find(VD);

3133 if (iter != LocalDeclMap.end()) {

3134 addr = iter->second;

3135

3136

3137

3138 } else if (VD->isStaticLocal()) {

3143

3144

3145 } else {

3146 llvm_unreachable("DeclRefExpr for Decl not entered in LocalDeclMap?");

3147 }

3148

3149

3154

3155

3157 VD->hasAttr()) {

3161 }

3162

3163

3164 bool isBlockByref = VD->isEscapingByref();

3165 if (isBlockByref) {

3167 }

3168

3169

3173

3174 bool isLocalStorage = VD->hasLocalStorage();

3175

3176 bool NonGCable = isLocalStorage &&

3178 !isBlockByref;

3179 if (NonGCable) {

3182 }

3183

3184 bool isImpreciseLifetime =

3185 (isLocalStorage && !VD->hasAttr());

3186 if (isImpreciseLifetime)

3189 return LV;

3190 }

3191

3192 if (const auto *FD = dyn_cast(ND))

3194

3195

3196

3197

3198 if (const auto *BD = dyn_cast(ND)) {

3199 if (E->refersToEnclosingVariableOrCapture()) {

3202 }

3203 return EmitLValue(BD->getBinding());

3204 }

3205

3206

3207

3208 if (const auto *GD = dyn_cast(ND))

3211

3212 if (const auto *TPO = dyn_cast(ND)) {

3215

3216 if (AS != T.getAddressSpace()) {

3218 auto PtrTy = llvm::PointerType::get(CGM.getLLVMContext(), TargetAS);

3220 CGM, ATPO.getPointer(), AS, T.getAddressSpace(), PtrTy);

3221 ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());

3222 }

3223

3225 }

3226

3227 llvm_unreachable("Unhandled DeclRefExpr");

3228}

3229

3231

3232 if (E->getOpcode() == UO_Extension)

3234

3236 switch (E->getOpcode()) {

3237 default: llvm_unreachable("Unknown unary operator lvalue!");

3238 case UO_Deref: {

3240 assert(T.isNull() && "CodeGenFunction::EmitUnaryOpLValue: Illegal type");

3241

3245 &TBAAInfo);

3248

3249

3250

3251

3252

3257 return LV;

3258 }

3259 case UO_Real:

3260 case UO_Imag: {

3262 assert(LV.isSimple() && "real/imag on non-ordinary l-value");

3263

3264

3265

3266 if (E->getOpcode() == UO_Real &&

3269 return LV;

3270 }

3271

3273

3275 (E->getOpcode() == UO_Real

3281 return ElemLV;

3282 }

3283 case UO_PreInc:

3284 case UO_PreDec: {

3286 bool isInc = E->getOpcode() == UO_PreInc;

3287

3290 else

3292 return LV;

3293 }

3294 }

3295}

3296

3300}

3301

3305}

3306

3308 auto SL = E->getFunctionName();

3309 assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");

3310 StringRef FnName = CurFn->getName();

3311 if (FnName.starts_with("\01"))

3312 FnName = FnName.substr(1);

3313 StringRef NameItems[] = {

3315 std::string GVName = llvm::join(NameItems, NameItems + 2, ".");

3316 if (auto *BD = dyn_cast_or_null(CurCodeDecl)) {

3317 std::string Name = std::string(SL->getString());

3318 if (!Name.empty()) {

3319 unsigned Discriminator =

3321 if (Discriminator)

3322 Name += "_" + Twine(Discriminator + 1).str();

3325 } else {

3326 auto C =

3329 }

3330 }

3333}

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3347

3349 return C;

3350

3353 bool IsBitInt = false;

3354

3359

3360

3361

3363

3365 " non positive amount of bits in __BitInt type");

3367 " too many bits in __BitInt type");

3368

3369

3370

3372 IsBitInt = true;

3373 }

3377 }

3378

3379

3380

3383 (intptr_t)T.getAsOpaquePtr(), StringRef(),

3384 StringRef(), {}, Buffer, {});

3385

3386 if (IsBitInt) {

3387

3388

3389 char S[6] = {'\0', '\0', '\0', '\0', '\0', '\0'};

3391 uint32_t Bits = EIT->getNumBits();

3392 llvm::support::endian::write32(S + 1, Bits,

3394 ? llvm::endianness::big

3395 : llvm::endianness::little);

3396 StringRef Str = StringRef(S, sizeof(S) / sizeof(decltype(S[0])));

3397 Buffer.append(Str);

3398 }

3399

3400 llvm::Constant *Components[] = {

3402 llvm::ConstantDataArray::getString(getLLVMContext(), Buffer)

3403 };

3404 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);

3405

3406 auto *GV = new llvm::GlobalVariable(

3408 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);

3409 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

3411

3412

3414

3415 return GV;

3416}

3417

3419 llvm::Type *TargetTy = IntPtrTy;

3420

3421 if (V->getType() == TargetTy)

3422 return V;

3423

3424

3425

3426 if (V->getType()->isFloatingPointTy()) {

3427 unsigned Bits = V->getType()->getPrimitiveSizeInBits().getFixedValue();

3428 if (Bits <= TargetTy->getIntegerBitWidth())

3430 Bits));

3431 }

3432

3433

3434 if (V->getType()->isIntegerTy() &&

3435 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())

3436 return Builder.CreateZExt(V, TargetTy);

3437

3438

3439 if (V->getType()->isPointerTy()) {

3443 }

3444 return Builder.CreatePtrToInt(V, TargetTy);

3445}

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3459

3462 StringRef FilenameString = PLoc.getFilename();

3463

3464 int PathComponentsToStrip =

3466 if (PathComponentsToStrip < 0) {

3467 assert(PathComponentsToStrip != INT_MIN);

3468 int PathComponentsToKeep = -PathComponentsToStrip;

3469 auto I = llvm::sys::path::rbegin(FilenameString);

3470 auto E = llvm::sys::path::rend(FilenameString);

3471 while (I != E && --PathComponentsToKeep)

3472 ++I;

3473

3474 FilenameString = FilenameString.substr(I - E);

3475 } else if (PathComponentsToStrip > 0) {

3476 auto I = llvm::sys::path::begin(FilenameString);

3477 auto E = llvm::sys::path::end(FilenameString);

3478 while (I != E && PathComponentsToStrip--)

3479 ++I;

3480

3481 if (I != E)

3482 FilenameString =

3483 FilenameString.substr(I - llvm::sys::path::begin(FilenameString));

3484 else

3485 FilenameString = llvm::sys::path::filename(FilenameString);

3486 }

3487

3488 auto FilenameGV =

3491 castllvm::GlobalVariable(

3492 FilenameGV.getPointer()->stripPointerCasts()));

3493 Filename = FilenameGV.getPointer();

3496 } else {

3499 }

3500

3503

3504 return llvm::ConstantStruct::getAnon(Data);

3505}

3506

3507namespace {

3508

3509enum class CheckRecoverableKind {

3510

3512

3513

3514 Recoverable,

3515

3517};

3518}

3519

3520static CheckRecoverableKind

3522 if (Ordinal == SanitizerKind::SO_Vptr)

3523 return CheckRecoverableKind::AlwaysRecoverable;

3524 else if (Ordinal == SanitizerKind::SO_Return ||

3525 Ordinal == SanitizerKind::SO_Unreachable)

3526 return CheckRecoverableKind::Unrecoverable;

3527 else

3528 return CheckRecoverableKind::Recoverable;

3529}

3530

3531namespace {

3532struct SanitizerHandlerInfo {

3533 char const *const Name;

3534 unsigned Version;

3535};

3536}

3537

3539#define SANITIZER_CHECK(Enum, Name, Version) {#Name, Version},

3541#undef SANITIZER_CHECK

3542};

3543

3545 llvm::FunctionType *FnType,

3548 CheckRecoverableKind RecoverKind, bool IsFatal,

3549 llvm::BasicBlock *ContBB, bool NoMerge) {

3550 assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);

3551 std::optional DL;

3552 if (!CGF.Builder.getCurrentDebugLocation()) {

3553

3555 }

3556 bool NeedsAbortSuffix =

3557 IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable;

3558 bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime;

3559 const SanitizerHandlerInfo &CheckInfo = SanitizerHandlers[CheckHandler];

3560 const StringRef CheckName = CheckInfo.Name;

3561 std::string FnName = "__ubsan_handle_" + CheckName.str();

3562 if (CheckInfo.Version && !MinimalRuntime)

3563 FnName += "_v" + llvm::utostr(CheckInfo.Version);

3564 if (MinimalRuntime)

3565 FnName += "_minimal";

3566 if (NeedsAbortSuffix)

3567 FnName += "_abort";

3568 bool MayReturn =

3569 !IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;

3570

3572 if (!MayReturn) {

3573 B.addAttribute(llvm::Attribute::NoReturn)

3574 .addAttribute(llvm::Attribute::NoUnwind);

3575 }

3576 B.addUWTableAttr(llvm::UWTableKind::Default);

3577

3579 FnType, FnName,

3581 llvm::AttributeList::FunctionIndex, B),

3582 true);

3584 NoMerge = NoMerge || !CGF.CGM.getCodeGenOpts().OptimizationLevel ||

3586 if (NoMerge)

3587 HandlerCall->addFnAttr(llvm::Attribute::NoMerge);

3588 if (!MayReturn) {

3589 HandlerCall->setDoesNotReturn();

3590 CGF.Builder.CreateUnreachable();

3591 } else {

3592 CGF.Builder.CreateBr(ContBB);

3593 }

3594}

3595

3597 ArrayRef<std::pair<llvm::Value *, SanitizerKind::SanitizerOrdinal>> Checked,

3601 assert(Checked.size() > 0);

3602 assert(CheckHandler >= 0 &&

3604 const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;

3605

3606 llvm::Value *FatalCond = nullptr;

3607 llvm::Value *RecoverableCond = nullptr;

3608 llvm::Value *TrapCond = nullptr;

3609 bool NoMerge = false;

3610 for (auto &[Check, Ord] : Checked) {

3611

3614 ? RecoverableCond

3615 : FatalCond;

3616 Cond = Cond ? Builder.CreateAnd(Cond, Check) : Check;

3617

3619 NoMerge = true;

3620 }

3621

3623 llvm::Value *Allow =

3625 llvm::ConstantInt::get(CGM.Int8Ty, CheckHandler));

3626

3627 for (llvm::Value **Cond : {&FatalCond, &RecoverableCond, &TrapCond}) {

3628 if (*Cond)

3629 *Cond = Builder.CreateOr(*Cond, Builder.CreateNot(Allow));

3630 }

3631 }

3632

3633 if (TrapCond)

3635 if (!FatalCond && !RecoverableCond)

3636 return;

3637

3638 llvm::Value *JointCond;

3639 if (FatalCond && RecoverableCond)

3640 JointCond = Builder.CreateAnd(FatalCond, RecoverableCond);

3641 else

3642 JointCond = FatalCond ? FatalCond : RecoverableCond;

3643 assert(JointCond);

3644

3645 CheckRecoverableKind RecoverKind = getRecoverableKind(Checked[0].second);

3646 assert(SanOpts.has(Checked[0].second));

3647#ifndef NDEBUG

3648 for (int i = 1, n = Checked.size(); i < n; ++i) {

3650 "All recoverable kinds in a single check must be same!");

3651 assert(SanOpts.has(Checked[i].second));

3652 }

3653#endif

3654

3656 llvm::BasicBlock *Handlers = createBasicBlock("handler." + CheckName);

3657 llvm::Instruction *Branch = Builder.CreateCondBr(JointCond, Cont, Handlers);

3658

3660 llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();

3661 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);

3663

3664

3665

3666

3670 Args.reserve(DynamicArgs.size() + 1);

3671 ArgTypes.reserve(DynamicArgs.size() + 1);

3672

3673

3674 if (!StaticArgs.empty()) {

3675 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);

3676 auto *InfoPtr = new llvm::GlobalVariable(

3678 llvm::GlobalVariable::PrivateLinkage, Info, "", nullptr,

3679 llvm::GlobalVariable::NotThreadLocal,

3681 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

3683 Args.push_back(InfoPtr);

3684 ArgTypes.push_back(Args.back()->getType());

3685 }

3686

3687 for (size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {

3689 ArgTypes.push_back(IntPtrTy);

3690 }

3691 }

3692

3693 llvm::FunctionType *FnType =

3694 llvm::FunctionType::get(CGM.VoidTy, ArgTypes, false);

3695

3696 if (!FatalCond || !RecoverableCond) {

3697

3698

3700 (FatalCond != nullptr), Cont, NoMerge);

3701 } else {

3702

3703

3704 llvm::BasicBlock *NonFatalHandlerBB =

3706 llvm::BasicBlock *FatalHandlerBB = createBasicBlock("fatal." + CheckName);

3707 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);

3710 NonFatalHandlerBB, NoMerge);

3713 Cont, NoMerge);

3714 }

3715

3717}

3718

3721 llvm::ConstantInt *TypeId, llvm::Value *Ptr,

3724

3725 llvm::BasicBlock *CheckBB = createBasicBlock("cfi.slowpath");

3726 llvm::BranchInst *BI = Builder.CreateCondBr(Cond, Cont, CheckBB);

3727

3729 llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();

3730 BI->setMetadata(llvm::LLVMContext::MD_prof, Node);

3731

3733

3735

3736 llvm::CallInst *CheckCall;

3737 llvm::FunctionCallee SlowPathFn;

3738 if (WithDiag) {

3739 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);

3740 auto *InfoPtr =

3741 new llvm::GlobalVariable(CGM.getModule(), Info->getType(), false,

3742 llvm::GlobalVariable::PrivateLinkage, Info);

3743 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

3745

3746 SlowPathFn = CGM.getModule().getOrInsertFunction(

3747 "__cfi_slowpath_diag",

3749 false));

3750 CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr, InfoPtr});

3751 } else {

3752 SlowPathFn = CGM.getModule().getOrInsertFunction(

3753 "__cfi_slowpath",

3755 CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr});

3756 }

3757

3759 castllvm::GlobalValue(SlowPathFn.getCallee()->stripPointerCasts()));

3760 CheckCall->setDoesNotThrow();

3761

3763}

3764

3765

3766

3770 QualType QInt64Ty = C.getIntTypeForBitwidth(64, false);

3771

3777 FnArgs.push_back(&ArgCallsiteTypeId);

3778 FnArgs.push_back(&ArgAddr);

3779 FnArgs.push_back(&ArgCFICheckFailData);

3782

3783 llvm::Function *F = llvm::Function::Create(

3785 llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);

3788 F->setAlignment(llvm::Align(4096));

3790

3791 llvm::LLVMContext &Ctx = M->getContext();

3792 llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);

3793

3795 llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);

3796 llvm::ReturnInst::Create(Ctx, nullptr, BB);

3797}

3798

3799

3800

3801

3802

3803

3804

3805

3807 SanitizerScope SanScope(this);

3813 Args.push_back(&ArgData);

3814 Args.push_back(&ArgAddr);

3815

3818

3819 llvm::Function *F = llvm::Function::Create(

3821 llvm::GlobalValue::WeakODRLinkage, "__cfi_check_fail", &CGM.getModule());

3822

3825 F->setVisibility(llvm::GlobalValue::HiddenVisibility);

3826

3829

3830

3831

3832

3834

3835 llvm::Value *Data =

3838 llvm::Value *Addr =

3841

3842

3843 llvm::Value *DataIsNotNullPtr =

3845 EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);

3846

3847 llvm::StructType *SourceLocationTy =

3849 llvm::StructType *CfiCheckFailDataTy =

3850 llvm::StructType::get(Int8Ty, SourceLocationTy, VoidPtrTy);

3851

3854

3857

3858 llvm::Value *AllVtables = llvm::MetadataAsValue::get(

3861 llvm::Value *ValidVtable = Builder.CreateZExt(

3863 {Addr, AllVtables}),

3865

3866 const std::pair<int, SanitizerKind::SanitizerOrdinal> CheckKinds[] = {

3871 {CFITCK_ICall, SanitizerKind::SO_CFIICall}};

3872

3874 Checks;

3875 for (auto CheckKindOrdinalPair : CheckKinds) {

3876 int Kind = CheckKindOrdinalPair.first;

3878 llvm::Value *Cond =

3879 Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty, Kind));

3881 EmitCheck(std::make_pair(Cond, Ordinal), SanitizerHandler::CFICheckFail,

3882 {}, {Data, Addr, ValidVtable});

3883 else

3884 EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail);

3885 }

3886

3888

3889

3891}

3892

3894 if (SanOpts.has(SanitizerKind::Unreachable)) {

3895 SanitizerScope SanScope(this);

3896 EmitCheck(std::make_pair(static_cast<llvm::Value *>(Builder.getFalse()),

3897 SanitizerKind::SO_Unreachable),

3898 SanitizerHandler::BuiltinUnreachable,

3900 }

3901 Builder.CreateUnreachable();

3902}

3903

3906 bool NoMerge) {

3908

3909

3910

3911 if ((int)TrapBBs.size() <= CheckHandlerID)

3912 TrapBBs.resize(CheckHandlerID + 1);

3913

3914 llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];

3915

3918

3919 if (TrapBB && !NoMerge) {

3920 auto Call = TrapBB->begin();

3921 assert(isallvm::CallInst(Call) && "Expected call in trap BB");

3922

3923 Call->applyMergedLocation(Call->getDebugLoc(),

3924 Builder.getCurrentDebugLocation());

3925 Builder.CreateCondBr(Checked, Cont, TrapBB);

3926 } else {

3928 Builder.CreateCondBr(Checked, Cont, TrapBB);

3930

3931 llvm::CallInst *TrapCall =

3933 llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID));

3934

3936 auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name",

3938 TrapCall->addFnAttr(A);

3939 }

3940 if (NoMerge)

3941 TrapCall->addFnAttr(llvm::Attribute::NoMerge);

3942 TrapCall->setDoesNotReturn();

3943 TrapCall->setDoesNotThrow();

3944 Builder.CreateUnreachable();

3945 }

3946

3948}

3949

3951 llvm::CallInst *TrapCall =

3953

3955 auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name",

3957 TrapCall->addFnAttr(A);

3958 }

3959

3961 TrapCall->addFnAttr(llvm::Attribute::NoMerge);

3962 return TrapCall;

3963}

3964

3969 "Array to pointer decay must have array source type!");

3970

3971

3974

3975

3976

3979

3980

3981

3983 assert(isallvm::ArrayType(Addr.getElementType()) &&

3984 "Expected pointer to array");

3986 }

3987

3988

3989

3990

3991

3992

3994 if (BaseInfo) *BaseInfo = LV.getBaseInfo();

3996

3998}

3999

4000

4001

4003

4004 const auto *CE = dyn_cast(E);

4005 if (!CE || CE->getCastKind() != CK_ArrayToPointerDecay)

4006 return nullptr;

4007

4008

4011 return nullptr;

4012

4013 return SubExpr;

4014}

4015

4017 llvm::Type *elemType,

4018 llvm::Value *ptr,

4020 bool inbounds,

4021 bool signedIndices,

4023 const llvm::Twine &name = "arrayidx") {

4024 if (inbounds) {

4027 name);

4028 } else {

4030 }

4031}

4032

4035 llvm::Type *elementType, bool inbounds,

4038 const llvm::Twine &name = "arrayidx") {

4039 if (inbounds) {

4042 align, name);

4043 } else {

4044 return CGF.Builder.CreateGEP(addr, indices, elementType, align, name);

4045 }

4046}

4047

4049 llvm::Value *idx,

4051

4052

4053 if (auto constantIdx = dyn_castllvm::ConstantInt(idx)) {

4054 CharUnits offset = constantIdx->getZExtValue() * eltSize;

4056

4057

4058 } else {

4060 }

4061}

4062

4066 do {

4069 return eltType;

4070}

4071

4073 return D && D->hasAttr();

4074}

4075

4077 if (E)

4078 return false;

4080 if (PointeeType.isNull())

4081 return false;

4082 if (const auto *BaseDecl = PointeeType->getAsRecordDecl())

4084 return false;

4085}

4086

4087

4091 return Addr;

4092

4093 llvm::Function *Fn =

4094 CGF.CGM.getIntrinsic(llvm::Intrinsic::preserve_static_offset);

4097}

4098

4099

4100

4103 return false;

4104

4105

4106

4107

4108

4109

4110

4111

4113 if (const auto *ME = dyn_cast(E))

4115

4116 if (const auto *DRE = dyn_cast(E)) {

4117 const auto *VarDef = dyn_cast(DRE->getDecl());

4118 if (!VarDef)

4119 return false;

4120

4121 const auto *PtrT = VarDef->getType()->getAs<PointerType>();

4122 if (!PtrT)

4123 return false;

4124

4127 if (const auto *RecT = dyn_cast(PointeeT))

4128 return RecT->getDecl()->hasAttr();

4129 return false;

4130 }

4131

4132 return false;

4133}

4134

4137 QualType eltType, bool inbounds,

4141 const llvm::Twine &name = "arrayidx") {

4142

4143#ifndef NDEBUG

4144 for (auto *idx : indices.drop_back())

4145 assert(isallvm::ConstantInt(idx) &&

4146 castllvm::ConstantInt(idx)->isZero());

4147#endif

4148

4149

4150

4153 }

4154

4155

4159

4162

4163 llvm::Value *eltPtr;

4164 auto LastIndex = dyn_castllvm::ConstantInt(indices.back());

4165 if (!LastIndex ||

4169 signedIndices, loc, eltAlign, name);

4170 return addr;

4171 } else {

4172

4173 unsigned idx = LastIndex->getZExtValue();

4174 llvm::DIType *DbgInfo = nullptr;

4177 eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(

4179 idx, DbgInfo);

4180 }

4181

4183}

4184

4185

4187 const FieldDecl *Field, int64_t &Offset) {

4190 unsigned FieldNo = 0;

4191

4193 if (FD == Field) {

4195 return true;

4196 }

4197

4198 QualType Ty = FD->getType();

4202 return true;

4203 }

4204

4206 ++FieldNo;

4207 }

4208

4209 return false;

4210}

4211

4212

4213

4214

4215

4216

4224

4225 if (FD1OuterRec != FD2OuterRec)

4226

4227 return std::optional<int64_t>();

4228

4229 int64_t FD1Offset = 0;

4231 return std::optional<int64_t>();

4232

4233 int64_t FD2Offset = 0;

4235 return std::optional<int64_t>();

4236

4237 return std::make_optional<int64_t>(FD1Offset - FD2Offset);

4238}

4239

4241 bool Accessed) {

4242

4243

4244 llvm::Value *IdxPre =

4245 (E->getLHS() == E->getIdx()) ? EmitScalarExpr(E->getIdx()) : nullptr;

4246 bool SignedIndices = false;

4247 auto EmitIdxAfterBase = [&, IdxPre](bool Promote) -> llvm::Value * {

4248 auto *Idx = IdxPre;

4249 if (E->getLHS() != E->getIdx()) {

4250 assert(E->getRHS() == E->getIdx() && "index was neither LHS nor RHS");

4252 }

4253

4256 SignedIndices |= IdxSigned;

4257

4258 if (SanOpts.has(SanitizerKind::ArrayBounds))

4260

4261

4262 if (Promote && Idx->getType() != IntPtrTy)

4263 Idx = Builder.CreateIntCast(Idx, IntPtrTy, IdxSigned, "idxprom");

4264

4265 return Idx;

4266 };

4267 IdxPre = nullptr;

4268

4269

4270

4272 !isa(E->getBase())) {

4273

4275 auto *Idx = EmitIdxAfterBase(false);

4276 assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");

4279 }

4280

4281

4282

4283

4284 if (isa(E->getBase())) {

4286 auto *Idx = EmitIdxAfterBase(true);

4288

4294 }

4295

4301

4302

4303

4305 auto *Idx = EmitIdxAfterBase(true);

4306

4307

4309

4310

4311

4312

4313

4314 if (getLangOpts().isSignedOverflowDefined()) {

4315 Idx = Builder.CreateMul(Idx, numElements);

4316 } else {

4317 Idx = Builder.CreateNSWMul(Idx, numElements);

4318 }

4319

4321 getLangOpts().isSignedOverflowDefined(),

4323

4325

4326

4327

4329 auto *Idx = EmitIdxAfterBase(true);

4330

4332 llvm::Value *InterfaceSizeVal =

4333 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.getQuantity());

4334

4335 llvm::Value *ScaledIdx = Builder.CreateMul(Idx, InterfaceSizeVal);

4336

4337

4338

4339

4340

4342

4343

4346 llvm::Value *EltPtr =

4348 ScaledIdx, false, SignedIndices, E->getExprLoc());

4349 Addr = Address(EltPtr, OrigBaseElemTy, EltAlign);

4351

4352

4353

4354

4355 assert(Array->getType()->isArrayType() &&

4356 "Array to pointer decay must have array source type!");

4358

4359

4360 if (const auto *ASE = dyn_cast(Array))

4362 else

4364 auto *Idx = EmitIdxAfterBase(true);

4365

4366 if (SanOpts.has(SanitizerKind::ArrayBounds)) {

4367

4368

4369

4370

4371

4372

4373

4375 getLangOpts().getStrictFlexArraysLevel();

4376

4377 if (const auto *ME = dyn_cast(Array);

4378 ME &&

4383 if (std::optional<int64_t> Diff =

4386

4387

4388

4391

4392 llvm::Type *CountTy = ConvertType(CountFD->getType());

4397 ".counted_by.load");

4398

4399

4401 Array->getType(), Accessed);

4402 }

4403 }

4404 }

4405 }

4406

4407

4410 *this, ArrayLV.getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},

4415 } else {

4416

4418 auto *Idx = EmitIdxAfterBase(true);

4421 getLangOpts().isSignedOverflowDefined(),

4422 SignedIndices, E->getExprLoc(), &ptrType,

4423 E->getBase());

4424 }

4425

4427

4432 }

4433 return LV;

4434}

4435

4438 if (Idx->getType() == IntPtrTy)

4439 return Idx;

4442}

4443

4445 assert(

4446 E->isIncomplete() &&

4447 "incomplete matrix subscript expressions should be rejected during Sema");

4449

4450

4453

4454 llvm::Value *NumRows = Builder.getIntN(

4455 RowIdx->getType()->getScalarSizeInBits(),

4457 llvm::Value *FinalIdx =

4458 Builder.CreateAdd(Builder.CreateMul(ColIdx, NumRows), RowIdx);

4462}

4463

4468 bool IsLowerBound) {

4470 if (auto *ASE = dyn_cast(Base->IgnoreParenImpCasts())) {

4475

4476

4477

4478 llvm::Type *NewTy = CGF.ConvertType(BaseTy);

4480

4481

4482

4484 assert(isallvm::ArrayType(Addr.getElementType()) &&

4485 "Expected pointer to array");

4487 }

4488

4490 }

4499 }

4501}

4502

4504 bool IsLowerBound) {

4505

4506 assert(E->isOpenACCArraySection() &&

4507 "OpenACC Array section codegen not implemented");

4508

4511 if (auto *AT = getContext().getAsArrayType(BaseTy))

4512 ResultExprTy = AT->getElementType();

4513 else

4515 llvm::Value *Idx = nullptr;

4516 if (IsLowerBound || E->getColonLocFirst().isInvalid()) {

4517

4518

4519

4520 if (auto *LowerBound = E->getLowerBound()) {

4521 Idx = Builder.CreateIntCast(

4523 LowerBound->getType()->hasSignedIntegerRepresentation());

4524 } else

4525 Idx = llvm::ConstantInt::getNullValue(IntPtrTy);

4526 } else {

4527

4528

4529

4531 auto *Length = E->getLength();

4532 llvm::APSInt ConstLength;

4533 if (Length) {

4534

4535 if (std::optionalllvm::APSInt CL = Length->getIntegerConstantExpr(C)) {

4537 Length = nullptr;

4538 }

4539 auto *LowerBound = E->getLowerBound();

4540 llvm::APSInt ConstLowerBound(PointerWidthInBits, false);

4541 if (LowerBound) {

4542 if (std::optionalllvm::APSInt LB =

4543 LowerBound->getIntegerConstantExpr(C)) {

4545 LowerBound = nullptr;

4546 }

4547 }

4548 if (!Length)

4549 --ConstLength;

4550 else if (!LowerBound)

4551 --ConstLowerBound;

4552

4553 if (Length || LowerBound) {

4554 auto *LowerBoundVal =

4555 LowerBound

4556 ? Builder.CreateIntCast(

4558 LowerBound->getType()->hasSignedIntegerRepresentation())

4559 : llvm::ConstantInt::get(IntPtrTy, ConstLowerBound);

4560 auto *LengthVal =

4561 Length

4562 ? Builder.CreateIntCast(

4564 Length->getType()->hasSignedIntegerRepresentation())

4565 : llvm::ConstantInt::get(IntPtrTy, ConstLength);

4566 Idx = Builder.CreateAdd(LowerBoundVal, LengthVal, "lb_add_len",

4567 false,

4568 getLangOpts().isSignedOverflowDefined());

4569 if (Length && LowerBound) {

4570 Idx = Builder.CreateSub(

4571 Idx, llvm::ConstantInt::get(IntPtrTy, 1), "idx_sub_1",

4572 false, getLangOpts().isSignedOverflowDefined());

4573 }

4574 } else

4575 Idx = llvm::ConstantInt::get(IntPtrTy, ConstLength + ConstLowerBound);

4576 } else {

4577

4580 : BaseTy;

4581 if (auto *VAT = C.getAsVariableArrayType(ArrayTy)) {

4582 Length = VAT->getSizeExpr();

4583 if (std::optionalllvm::APSInt L = Length->getIntegerConstantExpr(C)) {

4584 ConstLength = *L;

4585 Length = nullptr;

4586 }

4587 } else {

4588 auto *CAT = C.getAsConstantArrayType(ArrayTy);

4589 assert(CAT && "unexpected type for array initializer");

4590 ConstLength = CAT->getSize();

4591 }

4592 if (Length) {

4593 auto *LengthVal = Builder.CreateIntCast(

4595 Length->getType()->hasSignedIntegerRepresentation());

4596 Idx = Builder.CreateSub(

4597 LengthVal, llvm::ConstantInt::get(IntPtrTy, 1), "len_sub_1",

4598 false, getLangOpts().isSignedOverflowDefined());

4599 } else {

4601 --ConstLength;

4602 Idx = llvm::ConstantInt::get(IntPtrTy, ConstLength);

4603 }

4604 }

4605 }

4606 assert(Idx);

4607

4611 if (auto *VLA = getContext().getAsVariableArrayType(ResultExprTy)) {

4612

4613

4614

4617 BaseTy, VLA->getElementType(), IsLowerBound);

4618

4620

4621

4622

4623

4624

4625 if (getLangOpts().isSignedOverflowDefined())

4626 Idx = Builder.CreateMul(Idx, NumElements);

4627 else

4628 Idx = Builder.CreateNSWMul(Idx, NumElements);

4630 getLangOpts().isSignedOverflowDefined(),

4631 false, E->getExprLoc());

4633

4634

4635

4636

4637 assert(Array->getType()->isArrayType() &&

4638 "Array to pointer decay must have array source type!");

4640

4641

4642 if (const auto *ASE = dyn_cast(Array))

4644 else

4646

4647

4649 *this, ArrayLV.getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},

4650 ResultExprTy, getLangOpts().isSignedOverflowDefined(),

4651 false, E->getExprLoc());

4654 } else {

4657 ResultExprTy, IsLowerBound);

4659 getLangOpts().isSignedOverflowDefined(),

4660 false, E->getExprLoc());

4661 }

4662

4663 return MakeAddrLValue(EltPtr, ResultExprTy, BaseInfo, TBAAInfo);

4664}

4665

4668

4670

4671

4672 if (E->isArrow()) {

4673

4674

4679 Base = MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo, TBAAInfo);

4680 Base.getQuals().removeObjCGCAttr();

4681 } else if (E->getBase()->isGLValue()) {

4682

4683

4686 } else {

4687

4689 "Result must be a vector");

4691

4692

4697 }

4698

4701

4702

4704 E->getEncodedElementAccess(Indices);

4705

4706 if (Base.isSimple()) {

4707 llvm::Constant *CV =

4708 llvm::ConstantDataVector::get(getLLVMContext(), Indices);

4711 }

4712 assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");

4713

4714 llvm::Constant *BaseElts = Base.getExtVectorElts();

4716

4717 for (unsigned i = 0, e = Indices.size(); i != e; ++i)

4718 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));

4719 llvm::Constant *CV = llvm::ConstantVector::get(CElts);

4722}

4723

4728 }

4729

4730 Expr *BaseExpr = E->getBase();

4731

4733 if (E->isArrow()) {

4740 if (IsBaseCXXThis)

4741 SkippedChecks.set(SanitizerKind::Alignment, true);

4742 if (IsBaseCXXThis || isa(BaseExpr))

4743 SkippedChecks.set(SanitizerKind::Null, true);

4746 BaseLV = MakeAddrLValue(Addr, PtrTy, BaseInfo, TBAAInfo);

4747 } else

4749

4751 if (auto *Field = dyn_cast(ND)) {

4755

4756

4757

4762 }

4763 return LV;

4764 }

4765

4766 if (const auto *FD = dyn_cast(ND))

4768

4769 llvm_unreachable("Unhandled member declaration!");

4770}

4771

4772

4773

4774

4776 llvm::Value *ThisValue) {

4777 bool HasExplicitObjectParameter = false;

4778 const auto *MD = dyn_cast_if_present(CurCodeDecl);

4779 if (MD) {

4780 HasExplicitObjectParameter = MD->isExplicitObjectMemberFunction();

4781 assert(MD->getParent()->isLambda());

4782 assert(MD->getParent() == Field->getParent());

4783 }

4785 if (HasExplicitObjectParameter) {

4787 auto It = LocalDeclMap.find(D);

4788 assert(It != LocalDeclMap.end() && "explicit parameter not loaded?");

4789 Address AddrOfExplicitObject = It->getSecond();

4790 if (D->getType()->isReferenceType())

4793 else

4795 D->getType().getNonReferenceType());

4796

4797

4798 auto *ThisTy = D->getType().getNonReferenceType()->getAsCXXRecordDecl();

4799 auto *LambdaTy = cast(Field->getParent());

4800 if (ThisTy != LambdaTy) {

4803 LambdaLV.getAddress(), ThisTy, BasePathArray.begin(),

4804 BasePathArray.end(), false, SourceLocation());

4806 }

4807 } else {

4810 }

4812}

4813

4816}

4817

4818

4819

4821 unsigned FieldIndex) {

4822 unsigned I = 0, Skipped = 0;

4823

4825 if (I == FieldIndex)

4826 break;

4827 if (F->isUnnamedBitField())

4828 Skipped++;

4829 I++;

4830 }

4831

4832 return FieldIndex - Skipped;

4833}

4834

4835

4836

4841 if (Offset.isZero())

4842 return Base;

4845}

4846

4847

4848

4849

4850

4855

4857

4858 unsigned idx =

4860

4862}

4863

4869

4870 unsigned idx =

4872

4875}

4876

4879 if (!RD)

4880 return false;

4881

4882 if (RD->isDynamicClass())

4883 return true;

4884

4885 for (const auto &Base : RD->bases())

4887 return true;

4888

4890 if (hasAnyVptr(Field->getType(), Context))

4891 return true;

4892

4893 return false;

4894}

4895

4899

4915 if (!UseVolatile) {

4918 if (Idx != 0)

4919

4921 } else {

4926 DbgInfo);

4927 }

4928 }

4929 const unsigned SS =

4931

4932 llvm::Type *FieldIntTy = llvm::Type::getIntNTy(getLLVMContext(), SS);

4934 if (UseVolatile) {

4936 if (VolatileOffset)

4938 }

4939

4942

4946 }

4947

4948

4949

4950

4959 } else if (rec->isUnion()) {

4960

4962 } else {

4963

4964

4966 if (!FieldTBAAInfo.BaseType) {

4968 assert(!FieldTBAAInfo.Offset &&

4969 "Nonzero offset for an access with no base type!");

4970 }

4971

4972

4977 FieldTBAAInfo.Offset +=

4979

4980

4982 FieldTBAAInfo.Size =

4984 }

4985

4989 if (auto *ClassDef = dyn_cast(rec)) {

4991 ClassDef->isDynamicClass()) {

4992

4993

4994

4995

4996 auto *stripped =

4999 }

5000 }

5001

5004

5007

5008

5010

5013

5016 addr =

5021 }

5022

5025 } else {

5028

5030 else

5031

5033 }

5034

5035

5038 MakeAddrLValue(addr, FieldType, FieldBaseInfo, FieldTBAAInfo);

5042

5043

5044 RecordCVR = 0;

5046 }

5047

5048

5049

5051

5052 if (field->hasAttr())

5054

5057

5058

5061

5062 return LV;

5063}

5064

5069

5072

5074

5075

5077 V = V.withElementType(llvmType);

5078

5079

5080

5081

5087}

5088

5090 if (E->isFileScope()) {

5093 }

5095

5097

5099 const Expr *InitExpr = E->getInitializer();

5101

5103 true);

5104

5105

5106

5112

5114}

5115

5118

5120

5121

5122 assert(E->isTransparent() && "non-transparent glvalue init list");

5124}

5125

5126

5127

5128

5130 const Expr *Operand) {

5131 if (auto *ThrowExpr = dyn_cast(Operand->IgnoreParens())) {

5132 CGF.EmitCXXThrowExpr(ThrowExpr, false);

5133 return std::nullopt;

5134 }

5135

5137}

5138

5139namespace {

5140

5141

5142std::optional HandleConditionalOperatorLValueSimpleCase(

5144 const Expr *condExpr = E->getCond();

5145 bool CondExprBool;

5147 const Expr *Live = E->getTrueExpr(), *Dead = E->getFalseExpr();

5148 if (!CondExprBool)

5149 std::swap(Live, Dead);

5150

5152

5153 if (CondExprBool)

5156

5157

5158 if (auto *ThrowExpr = dyn_cast(Live->IgnoreParens())) {

5160 llvm::Type *ElemTy = CGF.ConvertType(Dead->getType());

5165 }

5167 }

5168 }

5169 return std::nullopt;

5170}

5171struct ConditionalInfo {

5172 llvm::BasicBlock *lhsBlock, *rhsBlock;

5173 std::optional LHS, RHS;

5174};

5175

5176

5177

5178template

5179ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF,

5181 const FuncTy &BranchGenFunc) {

5184 std::nullopt};

5185 llvm::BasicBlock *endBlock = CGF.createBasicBlock("cond.end");

5186

5187 CodeGenFunction::ConditionalEvaluation eval(CGF);

5190

5191

5194 eval.begin(CGF);

5195 Info.LHS = BranchGenFunc(CGF, E->getTrueExpr());

5196 eval.end(CGF);

5197 Info.lhsBlock = CGF.Builder.GetInsertBlock();

5198

5199 if (Info.LHS)

5200 CGF.Builder.CreateBr(endBlock);

5201

5202

5204 eval.begin(CGF);

5205 Info.RHS = BranchGenFunc(CGF, E->getFalseExpr());

5206 eval.end(CGF);

5207 Info.rhsBlock = CGF.Builder.GetInsertBlock();

5209

5210 return Info;

5211}

5212}

5213

5217

5219 "Unexpected conditional operator!");

5221 }

5222

5223 OpaqueValueMapping binding(*this, E);

5224 if (HandleConditionalOperatorLValueSimpleCase(*this, E))

5225 return;

5226

5230 });

5231}

5234 if (expr->isGLValue()) {

5235

5237 "Unexpected conditional operator!");

5239 }

5240

5241 OpaqueValueMapping binding(*this, expr);

5242 if (std::optional Res =

5243 HandleConditionalOperatorLValueSimpleCase(*this, expr))

5244 return *Res;

5245

5246 ConditionalInfo Info = EmitConditionalBlocks(

5249 });

5250

5251 if ((Info.LHS && !Info.LHS->isSimple()) ||

5252 (Info.RHS && !Info.RHS->isSimple()))

5254

5255 if (Info.LHS && Info.RHS) {

5256 Address lhsAddr = Info.LHS->getAddress();

5257 Address rhsAddr = Info.RHS->getAddress();

5259 lhsAddr, rhsAddr, Info.lhsBlock, Info.rhsBlock,

5260 Builder.GetInsertBlock(), expr->getType());

5262 std::max(Info.LHS->getBaseInfo().getAlignmentSource(),

5263 Info.RHS->getBaseInfo().getAlignmentSource());

5265 Info.LHS->getTBAAInfo(), Info.RHS->getTBAAInfo());

5267 TBAAInfo);

5268 } else {

5269 assert((Info.LHS || Info.RHS) &&

5270 "both operands of glvalue conditional are throw-expressions?");

5271 return Info.LHS ? *Info.LHS : *Info.RHS;

5272 }

5273}

5274

5275

5276

5277

5278

5279

5280

5281

5283 switch (E->getCastKind()) {

5284 case CK_ToVoid:

5285 case CK_BitCast:

5286 case CK_LValueToRValueBitCast:

5287 case CK_ArrayToPointerDecay:

5288 case CK_FunctionToPointerDecay:

5289 case CK_NullToMemberPointer:

5290 case CK_NullToPointer:

5291 case CK_IntegralToPointer:

5292 case CK_PointerToIntegral:

5293 case CK_PointerToBoolean:

5294 case CK_IntegralCast:

5295 case CK_BooleanToSignedIntegral:

5296 case CK_IntegralToBoolean:

5297 case CK_IntegralToFloating:

5298 case CK_FloatingToIntegral:

5299 case CK_FloatingToBoolean:

5300 case CK_FloatingCast:

5301 case CK_FloatingRealToComplex:

5302 case CK_FloatingComplexToReal:

5303 case CK_FloatingComplexToBoolean:

5304 case CK_FloatingComplexCast:

5305 case CK_FloatingComplexToIntegralComplex:

5306 case CK_IntegralRealToComplex:

5307 case CK_IntegralComplexToReal:

5308 case CK_IntegralComplexToBoolean:

5309 case CK_IntegralComplexCast:

5310 case CK_IntegralComplexToFloatingComplex:

5311 case CK_DerivedToBaseMemberPointer:

5312 case CK_BaseToDerivedMemberPointer:

5313 case CK_MemberPointerToBoolean:

5314 case CK_ReinterpretMemberPointer:

5315 case CK_AnyPointerToBlockPointerCast:

5316 case CK_ARCProduceObject:

5317 case CK_ARCConsumeObject:

5318 case CK_ARCReclaimReturnedObject:

5319 case CK_ARCExtendBlockObject:

5320 case CK_CopyAndAutoreleaseBlockObject:

5321 case CK_IntToOCLSampler:

5322 case CK_FloatingToFixedPoint:

5323 case CK_FixedPointToFloating:

5324 case CK_FixedPointCast:

5325 case CK_FixedPointToBoolean:

5326 case CK_FixedPointToIntegral:

5327 case CK_IntegralToFixedPoint:

5328 case CK_MatrixCast:

5329 case CK_HLSLVectorTruncation:

5330 case CK_HLSLArrayRValue:

5332

5333 case CK_Dependent:

5334 llvm_unreachable("dependent cast kind in IR gen!");

5335

5336 case CK_BuiltinFnToFnPtr:

5337 llvm_unreachable("builtin functions are handled elsewhere");

5338

5339

5340 case CK_NonAtomicToAtomic:

5341 case CK_AtomicToNonAtomic:

5343

5344 case CK_Dynamic: {

5347 const auto *DCE = cast(E);

5349 }

5350

5351 case CK_ConstructorConversion:

5352 case CK_UserDefinedConversion:

5353 case CK_CPointerToObjCPointerCast:

5354 case CK_BlockPointerToObjCPointerCast:

5355 case CK_LValueToRValue:

5357

5358 case CK_NoOp: {

5359

5360

5361

5363

5364 if (E->changesVolatileQualification())

5368 if (V.isValid()) {

5370 if (V.getElementType() != T)

5372 }

5373 }

5374 return LV;

5375 }

5376

5377 case CK_UncheckedDerivedToBase:

5378 case CK_DerivedToBase: {

5379 const auto *DerivedClassTy =

5381 auto *DerivedClassDecl = cast(DerivedClassTy->getDecl());

5382

5385

5386

5388 This, DerivedClassDecl, E->path_begin(), E->path_end(),

5389 false, E->getExprLoc());

5390

5391

5392

5393

5396 }

5397 case CK_ToUnion:

5399 case CK_BaseToDerived: {

5401 auto *DerivedClassDecl = cast(DerivedClassTy->getDecl());

5402

5404

5405

5407 LV.getAddress(), DerivedClassDecl, E->path_begin(), E->path_end(),

5408 false);

5409

5410

5411

5415

5416 if (SanOpts.has(SanitizerKind::CFIDerivedCast))

5420

5423 }

5424 case CK_LValueBitCast: {

5425

5426 const auto *CE = cast(E);

5427

5432

5433 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))

5437

5440 }

5441 case CK_AddressSpaceConversion: {

5451 }

5452 case CK_ObjCObjectLValueCast: {

5457 }

5458 case CK_ZeroToOCLOpaqueType:

5459 llvm_unreachable("NULL to OpenCL opaque type lvalue cast is not valid");

5460

5461 case CK_VectorSplat: {

5462

5466 }

5467 }

5468

5469 llvm_unreachable("Unhandled lvalue cast kind?");

5470}

5471

5475}

5476

5477std::pair<LValue, LValue>

5479

5482

5486

5487 if (E->isInOut())

5489 TempLV);

5490

5492 return std::make_pair(BaseLV, TempLV);

5493}

5494

5497

5499

5502

5503 llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);

5504

5506

5508 Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),

5509 LifetimeSize);

5511 return TempLV;

5512}

5513

5517

5518 llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator

5519 it = OpaqueLValues.find(e);

5520

5521 if (it != OpaqueLValues.end())

5522 return it->second;

5523

5524 assert(e->isUnique() && "LValue for a nonunique OVE hasn't been emitted");

5526}

5527

5531

5532 llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator

5533 it = OpaqueRValues.find(e);

5534

5535 if (it != OpaqueRValues.end())

5536 return it->second;

5537

5538 assert(e->isUnique() && "RValue for a nonunique OVE hasn't been emitted");

5540}

5541

5553

5554

5557

5558

5562 }

5563 llvm_unreachable("bad evaluation kind");

5564}

5565

5566

5567

5568

5569

5572 llvm::CallBase **CallOrInvoke) {

5573 llvm::CallBase *CallOrInvokeStorage;

5574 if (!CallOrInvoke) {

5575 CallOrInvoke = &CallOrInvokeStorage;

5576 }

5577

5578 auto AddCoroElideSafeOnExit = llvm::make_scope_exit([&] {

5579 if (E->isCoroElideSafe()) {

5580 auto *I = *CallOrInvoke;

5581 if (I)

5582 I->addFnAttr(llvm::Attribute::CoroElideSafe);

5583 }

5584 });

5585

5586

5589

5590 if (const auto *CE = dyn_cast(E))

5592

5593 if (const auto *CE = dyn_cast(E))

5595

5596

5597

5598 if (const auto *CE = dyn_cast(E))

5599 if (const auto *MD =

5600 dyn_cast_if_present(CE->getCalleeDecl());

5601 MD && MD->isImplicitObjectMemberFunction())

5603

5605

5609 }

5610

5613 }

5614

5616 nullptr, CallOrInvoke);

5617}

5618

5619

5622 llvm::CallBase **CallOrInvoke) {

5625 nullptr, CallOrInvoke);

5626}

5627

5628

5629

5630

5633 if (!PD->isInlineBuiltinDeclaration())

5634 return false;

5635 return true;

5636}

5637

5640

5642 std::string NoBuiltinFD = ("no-builtin-" + FD->getName()).str();

5643 std::string NoBuiltins = "no-builtins";

5644

5646 std::string FDInlineName = (Ident + ".inline").str();

5647

5648 bool IsPredefinedLibFunction =

5650 bool HasAttributeNoBuiltin =

5651 CGF.CurFn->getAttributes().hasFnAttr(NoBuiltinFD) ||

5652 CGF.CurFn->getAttributes().hasFnAttr(NoBuiltins);

5653

5654

5655

5656 if (CGF.CurFn->getName() != FDInlineName &&

5659 llvm::Function *Fn = llvm::castllvm::Function(CalleePtr);

5660 llvm::Module *M = Fn->getParent();

5661 llvm::Function *Clone = M->getFunction(FDInlineName);

5662 if (!Clone) {

5663 Clone = llvm::Function::Create(Fn->getFunctionType(),

5664 llvm::GlobalValue::InternalLinkage,

5665 Fn->getAddressSpace(), FDInlineName, M);

5666 Clone->addFnAttr(llvm::Attribute::AlwaysInline);

5667 }

5669 }

5670

5671

5672

5673

5674

5675

5676

5677 else if (!IsPredefinedLibFunction || !HasAttributeNoBuiltin)

5679 }

5680

5683 FD->hasAttr())

5685 castllvm::GlobalValue(CalleePtr->stripPointerCasts()));

5686

5688}

5689

5692

5693

5694 if (auto ICE = dyn_cast(E)) {

5695 if (ICE->getCastKind() == CK_FunctionToPointerDecay ||

5696 ICE->getCastKind() == CK_BuiltinFnToFnPtr) {

5697 return EmitCallee(ICE->getSubExpr());

5698 }

5699

5700

5701 } else if (auto DRE = dyn_cast(E)) {

5702 if (auto FD = dyn_cast(DRE->getDecl())) {

5704 }

5705 } else if (auto ME = dyn_cast(E)) {

5706 if (auto FD = dyn_cast(ME->getMemberDecl())) {

5709 }

5710

5711

5712 } else if (auto NTTP = dyn_cast(E)) {

5713 return EmitCallee(NTTP->getReplacement());

5714

5715

5716 } else if (auto PDE = dyn_cast(E)) {

5718 }

5719

5720

5721 llvm::Value *calleePtr;

5726 } else {

5729 }

5731

5733 if (const auto *VD =

5736

5739 CGCallee callee(calleeInfo, calleePtr, pointerAuth);

5740 return callee;

5741}

5742

5744

5745 if (E->getOpcode() == BO_Comma) {

5749 }

5750

5751 if (E->getOpcode() == BO_PtrMemD ||

5752 E->getOpcode() == BO_PtrMemI)

5754

5755 assert(E->getOpcode() == BO_Assign && "unexpected binary l-value");

5756

5757

5758

5759

5765

5768

5769

5773 break;

5774 }

5775

5776

5777

5779 llvm::Value *Previous = nullptr;

5781

5782

5783

5785 llvm::Value *RHS =

5788 } else

5790

5792

5795

5797 llvm::Value *Result = nullptr;

5798

5799

5800 if (SanOpts.has(SanitizerKind::ImplicitBitfieldConversion))

5802 else

5804

5805

5806

5811 } else

5813

5816 E->getLHS());

5817 return LV;

5818 }

5819

5822

5824

5825

5826

5829

5831 }

5832 llvm_unreachable("bad evaluation kind");

5833}

5834

5835

5836

5838

5840

5841

5842

5844 return LHS;

5845}

5846

5848 llvm::CallBase **CallOrInvoke) {

5850

5854

5855 assert(E->getCallReturnType(getContext())->isReferenceType() &&

5856 "Can't have a scalar return unless the return type is a "

5857 "reference type!");

5858

5860}

5861

5863

5865}

5866

5869 && "binding l-value to type which needs a temporary");

5873}

5874

5878}

5879

5883}

5884

5888}

5889

5897}

5898

5901

5905

5906 assert(E->getMethodDecl()->getReturnType()->isReferenceType() &&

5907 "Can't have a scalar return unless the return type is a "

5908 "reference type!");

5909

5911}

5912

5917}

5918

5922}

5923

5924llvm::Value *

5929 return Builder.CreateZExtOrTrunc(OffsetValue,

5931}

5932

5934 llvm::Value *BaseValue,

5936 unsigned CVRQualifiers) {

5938 Ivar, CVRQualifiers);

5939}

5940

5942

5943 llvm::Value *BaseValue = nullptr;

5944 const Expr *BaseExpr = E->getBase();

5947 if (E->isArrow()) {

5951 } else {

5953 BaseValue = BaseLV.getPointer(*this);

5954 ObjectTy = BaseExpr->getType();

5956 }

5957

5962 return LV;

5963}

5964

5966

5970}

5971

5975 llvm::Value *Chain,

5976 llvm::CallBase **CallOrInvoke,

5978

5979

5981 "Call must have function pointer type!");

5982

5983 const Decl *TargetDecl =

5985

5986 assert((!isa_and_present(TargetDecl) ||

5987 !cast(TargetDecl)->isImmediateFunction()) &&

5988 "trying to emit a call to an immediate function");

5989

5991

5992 auto PointeeType = cast(CalleeType)->getPointeeType();

5993

5995

5996 if (SanOpts.has(SanitizerKind::Function) &&

5997 (!TargetDecl || !isa(TargetDecl)) &&

5998 !isa(PointeeType)) {

5999 if (llvm::Constant *PrefixSig =

6001 SanitizerScope SanScope(this);

6003

6004 llvm::Type *PrefixSigType = PrefixSig->getType();

6005 llvm::StructType *PrefixStructTy = llvm::StructType::get(

6006 CGM.getLLVMContext(), {PrefixSigType, Int32Ty}, true);

6007

6008 llvm::Value *CalleePtr = Callee.getFunctionPointer();

6010

6012 Address(CalleePtr, CalleePtr->getType(),

6015 Callee.getPointerAuthInfo(), nullptr);

6017 }

6018

6019

6020

6021

6022

6023

6024

6025

6026

6027

6028 llvm::Value *AlignedCalleePtr;

6030 llvm::Value *CalleeAddress =

6032 llvm::Value *Mask = llvm::ConstantInt::get(IntPtrTy, ~1);

6033 llvm::Value *AlignedCalleeAddress =

6034 Builder.CreateAnd(CalleeAddress, Mask);

6035 AlignedCalleePtr =

6036 Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());

6037 } else {

6038 AlignedCalleePtr = CalleePtr;

6039 }

6040

6041 llvm::Value *CalleePrefixStruct = AlignedCalleePtr;

6042 llvm::Value *CalleeSigPtr =

6044 llvm::Value *CalleeSig =

6046 llvm::Value *CalleeSigMatch = Builder.CreateICmpEQ(CalleeSig, PrefixSig);

6047

6049 llvm::BasicBlock *TypeCheck = createBasicBlock("typecheck");

6050 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);

6051

6057 llvm::Value *CalleeTypeHashMatch =

6058 Builder.CreateICmpEQ(CalleeTypeHash, TypeHash);

6061 EmitCheck(std::make_pair(CalleeTypeHashMatch, SanitizerKind::SO_Function),

6062 SanitizerHandler::FunctionTypeMismatch, StaticData,

6063 {CalleePtr});

6064

6067 }

6068 }

6069

6070 const auto *FnType = cast(PointeeType);

6071

6072

6073

6074 if (SanOpts.has(SanitizerKind::CFIICall) &&

6075 (!TargetDecl || !isa(TargetDecl))) {

6076 SanitizerScope SanScope(this);

6078

6079 llvm::Metadata *MD;

6082 else

6084

6085 llvm::Value *TypeId = llvm::MetadataAsValue::get(getLLVMContext(), MD);

6086

6087 llvm::Value *CalleePtr = Callee.getFunctionPointer();

6088 llvm::Value *TypeTest = Builder.CreateCall(

6089 CGM.getIntrinsic(llvm::Intrinsic::type_test), {CalleePtr, TypeId});

6090

6092 llvm::Constant *StaticData[] = {

6096 };

6097 if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && CrossDsoTypeId) {

6099 CalleePtr, StaticData);

6100 } else {

6101 EmitCheck(std::make_pair(TypeTest, SanitizerKind::SO_CFIICall),

6102 SanitizerHandler::CFICheckFail, StaticData,

6103 {CalleePtr, llvm::UndefValue::get(IntPtrTy)});

6104 }

6105 }

6106

6108 if (Chain)

6110

6111

6112

6113

6114

6115

6116

6118 bool StaticOperator = false;

6119 if (auto *OCE = dyn_cast(E)) {

6120 if (OCE->isAssignmentOp())

6122 else {

6123 switch (OCE->getOperator()) {

6124 case OO_LessLess:

6125 case OO_GreaterGreater:

6126 case OO_AmpAmp:

6127 case OO_PipePipe:

6128 case OO_Comma:

6129 case OO_ArrowStar:

6131 break;

6132 default:

6133 break;

6134 }

6135 }

6136

6137 if (const auto *MD =

6138 dyn_cast_if_present(OCE->getCalleeDecl());

6139 MD && MD->isStatic())

6140 StaticOperator = true;

6141 }

6142

6144 if (StaticOperator) {

6145

6146

6148 Arguments = drop_begin(Arguments, 1);

6149 }

6150 EmitCallArgs(Args, dyn_cast(FnType), Arguments,

6151 E->getDirectCallee(), 0, Order);

6152

6154 Args, FnType, Chain);

6155

6156 if (ResolvedFnInfo)

6157 *ResolvedFnInfo = &FnInfo;

6158

6159

6160

6161

6163 isa(E) &&

6164 (!TargetDecl || !isa(TargetDecl))) {

6165 llvm::Value *Handle = Callee.getFunctionPointer();

6169 }

6170 llvm::CallBase *LocalCallOrInvoke = nullptr;

6173

6174

6175

6177 if (auto *CalleeDecl = dyn_cast_or_null(TargetDecl)) {

6180 DI->EmitFuncDeclForCallSite(LocalCallOrInvoke,

6181 DI->getFunctionType(CalleeDecl, ResTy, Args),

6182 CalleeDecl);

6183 }

6184 }

6185 if (CallOrInvoke)

6186 *CallOrInvoke = LocalCallOrInvoke;

6187

6188 return Call;

6189}

6190

6194 if (E->getOpcode() == BO_PtrMemI) {

6196 } else {

6198 }

6199

6202

6207 &TBAAInfo);

6208

6209 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);

6210}

6211

6212

6213

6225 }

6226 llvm_unreachable("bad evaluation kind");

6227}

6228

6230 assert(Val->getType()->isFPOrFPVectorTy());

6231 if (Accuracy == 0.0 || !isallvm::Instruction(Val))

6232 return;

6233

6235 llvm::MDNode *Node = MDHelper.createFPMath(Accuracy);

6236

6237 castllvm::Instruction(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node);

6238}

6239

6241 llvm::Type *EltTy = Val->getType()->getScalarType();

6242 if (!EltTy->isFloatTy())

6243 return;

6244

6249

6250

6251

6252

6253

6254

6255

6256

6258 }

6259}

6260

6262 llvm::Type *EltTy = Val->getType()->getScalarType();

6263 if (!EltTy->isFloatTy())

6264 return;

6265

6270

6271

6272

6273

6274

6275

6276

6277

6279 }

6280}

6281

6282namespace {

6283 struct LValueOrRValue {

6286 };

6287}

6288

6291 bool forLValue,

6294

6295

6296 const Expr *resultExpr = E->getResultExpr();

6297 LValueOrRValue result;

6298

6300 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {

6301 const Expr *semantic = *i;

6302

6303

6304

6305 if (const auto *ov = dyn_cast(semantic)) {

6306

6307 if (ov->isUnique()) {

6308 assert(ov != resultExpr &&

6309 "A unique OVE cannot be used as the result expression");

6310 continue;

6311 }

6312

6313

6314

6315 typedef CodeGenFunction::OpaqueValueMappingData OVMA;

6316 OVMA opaqueData;

6317 if (ov == resultExpr && ov->isPRValue() && !forLValue &&

6319 CGF.EmitAggExpr(ov->getSourceExpr(), slot);

6322 opaqueData = OVMA::bind(CGF, ov, LV);

6323 result.RV = slot.asRValue();

6324

6325

6326 } else {

6327 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());

6328

6329

6330 if (ov == resultExpr) {

6331 if (forLValue)

6333 else

6335 }

6336 }

6337

6338 opaques.push_back(opaqueData);

6339

6340

6341

6342 } else if (semantic == resultExpr) {

6343 if (forLValue)

6344 result.LV = CGF.EmitLValue(semantic);

6345 else

6346 result.RV = CGF.EmitAnyExpr(semantic, slot);

6347

6348

6349 } else {

6351 }

6352 }

6353

6354

6355 for (unsigned i = 0, e = opaques.size(); i != e; ++i)

6356 opaques[i].unbind(CGF);

6357

6358 return result;

6359}

6360

6364}

6365

6368}

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 llvm::Value * emitHashMix(CGBuilderTy &Builder, llvm::Value *Acc, llvm::Value *Ptr)

static const Expr * isSimpleArrayDecayOperand(const Expr *E)

isSimpleArrayDecayOperand - If the specified expr is a simple decay from an array to pointer,...

static bool hasBooleanRepresentation(QualType Ty)

static bool getFieldOffsetInBits(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *Field, int64_t &Offset)

The offset of a field from the beginning of the record.

static bool hasBPFPreserveStaticOffset(const RecordDecl *D)

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 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 CheckRecoverableKind getRecoverableKind(SanitizerKind::SanitizerOrdinal Ordinal)

static llvm::Value * emitArraySubscriptGEP(CodeGenFunction &CGF, llvm::Type *elemType, llvm::Value *ptr, ArrayRef< llvm::Value * > indices, bool inbounds, bool signedIndices, SourceLocation loc, const llvm::Twine &name="arrayidx")

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 LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc)

static bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD, const FieldDecl *Field, RecIndicesTy &Indices)

static bool OnlyHasInlineBuiltinDeclaration(const FunctionDecl *FD)

static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD)

static bool hasAnyVptr(const QualType Type, const ASTContext &Context)

static bool IsPreserveAIArrayBase(CodeGenFunction &CGF, const Expr *ArrayBase)

Given an array base, check whether its member access belongs to a record with preserve_access_index a...

static Address emitDeclTargetVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T)

static bool canEmitSpuriousReferenceToVariable(CodeGenFunction &CGF, const DeclRefExpr *E, const VarDecl *VD)

Determine whether we can emit a reference to VD from the current context, despite not necessarily hav...

VariableTypeDescriptorKind

@ TK_Float

A floating-point type.

@ TK_Unknown

Any other type. The value representation is unspecified.

@ TK_Integer

An integer type.

@ TK_BitInt

An _BitInt(N) type.

static CharUnits getArrayElementAlign(CharUnits arrayAlign, llvm::Value *idx, CharUnits eltSize)

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 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, bool NoMerge)

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)

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.

static QualType getPointeeType(const MemRegion *R)

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

bool isTypeIgnoredBySanitizer(const SanitizerMask &Mask, const QualType &Ty) const

Check if a type can have its sanitizer instrumentation elided based on its presence within an ignorel...

QualType getPointerDiffType() const

Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.

const NoSanitizeList & getNoSanitizeList() const

llvm::DenseMap< const CXXMethodDecl *, CXXCastPath > LambdaCastPaths

For capturing lambdas with an explicit object parameter whose type is derived from the lambda type,...

CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const

Return a conservative estimate of the alignment of the specified decl D.

uint64_t getTypeSize(QualType T) const

Return the size of the specified (complete) type T, in bits.

CharUnits getTypeSizeInChars(QualType T) const

Return the size of the specified (complete) type T, in characters.

const VariableArrayType * getAsVariableArrayType(QualType T) const

CharUnits toCharUnitsFromBits(int64_t BitSize) const

Convert a size in bits to a size in characters.

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...

This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...

static QualType getBaseOriginalType(const Expr *Base)

Return original type of the base expression for array section.

ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.

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".

A fixed int type of a specified bitwidth.

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.

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...

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...

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 SanitizeMergeHandlers

Set of sanitizer checks that can merge handlers (smaller code size at the expense of debuggability).

PointerAuthOptions PointerAuth

Configuration for pointer-signing.

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...

virtual llvm::FixedVectorType * getOptimalVectorMemoryType(llvm::FixedVectorType *T, const LangOptions &Opt) const

Returns the optimal vector memory type based on the given vector type.

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 forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)

static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)

forAddr - Make a slot for an aggregate value.

A scoped helper to set the current 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.

bool containsFieldDecl(const FieldDecl *FD) const

CallArgList - Type for representing both the value and type of arguments in a call.

void add(RValue rvalue, QualType type)

void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse, const Expr *writebackExpr=nullptr, llvm::Value *lifetimeSz=nullptr)

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 OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e)

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)

llvm::Value * GetVTablePtr(Address This, llvm::Type *VTableTy, const CXXRecordDecl *VTableClass, VTableAuthMode AuthMode=VTableAuthMode::Authenticate)

GetVTablePtr - Return the Value of the vtable pointer member pointed to by This.

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...

RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)

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 EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)

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)

LValue EmitCallExprLValue(const CallExpr *E, llvm::CallBase **CallOrInvoke=nullptr)

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.

void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, bool NoMerge=false)

Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...

LValue EmitHLSLArrayAssignLValue(const BinaryOperator *E)

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,...

LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args, QualType Ty)

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::Value * EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)

Build an expression accessing the "counted_by" field.

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 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.

bool InNoMergeAttributedStmt

True if the current statement has nomerge attribute.

LValue EmitUnsupportedLValue(const Expr *E, const char *Name)

EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...

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...

void markStmtMaybeUsed(const Stmt *S)

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 * EmitMatrixIndexExpr(const Expr *E)

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 EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)

Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)

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 ...

void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerKind::SanitizerOrdinal > > 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...

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)

RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke=nullptr)

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)

llvm::Value * authPointerToPointerCast(llvm::Value *ResultPtr, QualType SourceType, QualType DestType)

void SetSqrtFPAccuracy(llvm::Value *Val)

Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.

RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)

EmitCall - Generate a call of the given function, expecting the given result type,...

RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())

void EmitCfiSlowPathCheck(SanitizerKind::SanitizerOrdinal Ordinal, llvm::Value *Cond, llvm::ConstantInt *TypeId, llvm::Value *Ptr, ArrayRef< llvm::Constant * > StaticArgs)

Emit a slow path cross-DSO CFI check which calls __cfi_slowpath if Cond if false.

llvm::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 EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src, ExprValueKind SrcKind)

EmitAggFinalDestCopy - Emit copy of the specified aggregate into destination address.

void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)

LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)

std::pair< LValue, LValue > EmitHLSLOutArgLValues(const HLSLOutArgExpr *E, QualType Ty)

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)

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.

llvm::Value * GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)

static Destroyer destroyARCWeak

llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields

CleanupKind getCleanupKind(QualType::DestructionKind kind)

void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)

RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke)

llvm::Type * ConvertType(QualType T)

llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)

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)

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.

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

LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)

Address GetAddrOfLocalVar(const VarDecl *VD)

GetAddrOfLocalVar - Return the address of a local variable.

LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)

void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)

void EmitInitializationToLValue(const Expr *E, LValue LV, AggValueSlot::IsZeroed_t IsZeroed=AggValueSlot::IsNotZeroed)

EmitInitializationToLValue - Emit an initializer to an LValue.

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)

llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)

LValue EmitStmtExprLValue(const StmtExpr *E)

RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot(), llvm::CallBase **CallOrInvoke=nullptr)

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.

RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})

Like EmitLoadOfLValue but also handles complex and aggregate types.

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)

llvm::Type * convertTypeForLoadStore(QualType ASTTy, llvm::Type *LLVMTy=nullptr)

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::Constant * getRawFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)

Return a function pointer for a reference to the given function.

llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)

llvm::Constant * 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)

llvm::Constant * getFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)

Return the ABI-correct function pointer value for a reference to the given function.

const ABIInfo & getABIInfo()

DiagnosticsEngine & getDiags() const

void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)

Run some code with "sufficient" stack space.

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.

CGPointerAuthInfo getFunctionPointerAuthInfo(QualType T)

Return the abstract pointer authentication schema for a pointer to the given function type.

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()

llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys={})

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.

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.

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.

llvm::Type * ConvertTypeForMem(QualType T)

ConvertTypeForMem - Convert type T into a llvm::Type.

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.

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

RValue asAggregateRValue() const

CharUnits getAlignment() const

llvm::Value * getPointer(CodeGenFunction &CGF) const

llvm::Value * getMatrixIdx() const

llvm::Value * getGlobalReg() const

static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)

const Qualifiers & getQuals() const

static LValue MakeExtVectorElt(Address Addr, llvm::Constant *Elts, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)

Address getAddress() const

unsigned getVRQualifiers() const

void setThreadLocalRef(bool Value)

void setGlobalObjCRef(bool Value)

bool isExtVectorElt() const

llvm::Value * getVectorIdx() const

void setNontemporal(bool Value)

LValueBaseInfo getBaseInfo() const

void setARCPreciseLifetime(ARCPreciseLifetime_t value)

const CGBitFieldInfo & getBitFieldInfo() const

bool isThreadLocalRef() const

KnownNonNull_t isKnownNonNull() const

TBAAAccessInfo getTBAAInfo() const

void setNonGC(bool Value)

Address getVectorAddress() const

bool isNontemporal() const

static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)

Create a new object to represent a bit-field access.

static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)

void setAddress(Address address)

void setBaseIvarExp(Expr *V)

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].

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.

RecordDecl * getOuterLexicalRecordContext()

Retrieve the outermost lexically enclosing record context.

A reference to a declared variable, function, enum, etc.

bool refersToEnclosingVariableOrCapture() const

Does this DeclRefExpr refer to an enclosing local or a captured variable?

static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)

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 isLValue() const

isLValue - True if this expression is an "l-value" according to the rules of the current language.

bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const

EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...

Decl * getReferencedDeclOfCallee()

bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const

HasSideEffects - This routine returns true for all those expressions which have any effect other than...

Expr * IgnoreImpCasts() LLVM_READONLY

Skip past any implicit casts which might surround this expression until reaching a fixed point.

SourceLocation getExprLoc() const LLVM_READONLY

getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...

bool refersToBitField() const

Returns true if this expression is a gl-value that potentially refers to a bit-field.

bool 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 ...

Represents a member of a struct/union/class.

bool isBitField() const

Determines whether this field is a bitfield.

unsigned getFieldIndex() const

Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...

const RecordDecl * getParent() const

Returns the parent of this field declaration, which is the struct in which this field is defined.

const FieldDecl * findCountedByField() const

Find the FieldDecl specified in a FAM's "counted_by" attribute.

FullExpr - Represents a "full-expression" node.

const Expr * getSubExpr() const

Represents a function declaration or definition.

unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const

Returns a value indicating whether this function corresponds to a builtin function.

Represents a prototype with parameter type info, e.g.

GlobalDecl - represents a global declaration.

const Decl * getDecl() const

This class represents temporary values used to represent inout and out arguments in HLSL.

Describes an C or C++ initializer list.

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.

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.

An expression that sends a message to the given Objective-C object or class.

Represents a class type in Objective C.

ObjCSelectorExpr used for @selector in Objective-C.

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 parenthesized expression, e.g.

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

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.

const Expr *const * const_semantics_iterator

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 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.

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.

const Type * getTypeForDecl() const

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 isConstantArrayType() const

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.

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 isBitIntType() const

bool isAnyComplexType() const

const Type * getBaseElementTypeUnsafe() const

Get the base element type of this type, potentially discarding type qualifiers.

bool isAtomicType() const

bool isVariablyModifiedType() const

Whether this type is a variably-modified type (C99 6.7.5).

bool 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

bool isSubscriptableVectorType() const

const T * getAs() const

Member-template getAs'.

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),...

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 ...

bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD)

isEmptyFieldForLayout - Return true iff the field is "empty", that is, either a zero-width bit-field ...

@ EHCleanup

Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...

static AlignmentSource getFieldAlignmentSource(AlignmentSource Source)

Given that the base address has the given alignment source, what's our confidence in the alignment of...

const internal::VariadicAllOfMatcher< Type > type

Matches Types in the clang AST.

const AstTypeMatcher< ArrayType > arrayType

Matches all kinds of arrays.

const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr

Matches expressions.

const AstTypeMatcher< FunctionType > functionType

Matches FunctionType nodes.

constexpr Variable var(Literal L)

Returns the variable of L.

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 IsNonNull(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:🆑:opt< bool > ClSanitizeGuardChecks

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.

PointerAuthSchema FunctionPointers

The ABI for C function pointers.

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