LLVM: lib/Transforms/Instrumentation/TypeSanitizer.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

40

41#include

42

43using namespace llvm;

44

45#define DEBUG_TYPE "tysan"

46

51

53 "__tysan_shadow_memory_address";

55

60

62 "tysan-outline-instrumentation",

63 cl::desc("Uses function calls for all TySan instrumentation, reducing "

64 "ELF size"),

66

68 "tysan-verify-outlined-instrumentation",

69 cl::desc("Check types twice with both inlined instrumentation and "

70 "function calls. This verifies that they behave the same."),

72

73STATISTIC(NumInstrumentedAccesses, "Number of instrumented accesses");

74

75namespace {

76

77

78

79struct TypeSanitizer {

80 TypeSanitizer(Module &M);

82 void instrumentGlobals(Module &M);

83

84private:

86 TypeDescriptorsMapTy;

88

89 void initializeCallbacks(Module &M);

90

93

94 bool instrumentWithShadowUpdate(IRBuilder<> &IRB, const MDNode *TBAAMD,

96 bool IsWrite, Value *ShadowBase,

97 Value *AppMemMask, bool ForceSetType,

98 bool SanitizeFunction,

99 TypeDescriptorsMapTy &TypeDescriptors,

101

102

103

106

107 std::string getAnonymousStructIdentifier(const MDNode *MD,

108 TypeNameMapTy &TypeNames);

109 bool generateTypeDescriptor(const MDNode *MD,

110 TypeDescriptorsMapTy &TypeDescriptors,

111 TypeNameMapTy &TypeNames, Module &M);

112 bool generateBaseTypeDescriptor(const MDNode *MD,

113 TypeDescriptorsMapTy &TypeDescriptors,

114 TypeNameMapTy &TypeNames, Module &M);

115

116 const Triple TargetTriple;

117 Regex AnonNameRegex;

118 Type *IntptrTy;

121

122

125

129

130

131 Function *TysanGlobalsSetTypeFunction;

132};

133}

134

135TypeSanitizer::TypeSanitizer(Module &M)

136 : TargetTriple(M.getTargetTriple()),

137 AnonNameRegex("^_ZTS.*N[1-9][0-9]*_GLOBAL__N") {

139 IntptrTy = DL.getIntPtrType(M.getContext());

140 PtrShift = countr_zero(IntptrTy->getPrimitiveSizeInBits() / 8);

141

142 TysanGlobalsSetTypeFunction = M.getFunction("__tysan_set_globals_types");

143 initializeCallbacks(M);

144}

145

146void TypeSanitizer::initializeCallbacks(Module &M) {

151

152 AttributeList Attr;

153 Attr = Attr.addFnAttribute(M.getContext(), Attribute::NoUnwind);

154

155 TysanCheck =

156 M.getOrInsertFunction(kTysanCheckName, Attr, IRB.getVoidTy(),

157 IRB.getPtrTy(),

158 OrdTy,

159 IRB.getPtrTy(),

160 OrdTy

161 );

162

163 TysanCtorFunction =

165

166 TysanIntrumentMemInst = M.getOrInsertFunction(

167 "__tysan_instrument_mem_inst", Attr, IRB.getVoidTy(),

168 IRB.getPtrTy(),

169 IRB.getPtrTy(),

170 U64Ty,

171 BoolType

172 );

173

174 TysanInstrumentWithShadowUpdate = M.getOrInsertFunction(

175 "__tysan_instrument_with_shadow_update", Attr, IRB.getVoidTy(),

176 IRB.getPtrTy(),

177 IRB.getPtrTy(),

178 BoolType,

179 U64Ty,

180 OrdTy

181 );

182

183 TysanSetShadowType = M.getOrInsertFunction(

184 "__tysan_set_shadow_type", Attr, IRB.getVoidTy(),

185 IRB.getPtrTy(),

186 IRB.getPtrTy(),

187 U64Ty

188 );

189}

190

191void TypeSanitizer::instrumentGlobals(Module &M) {

192 TysanGlobalsSetTypeFunction = nullptr;

193

194 NamedMDNode *Globals = M.getNamedMetadata("llvm.tysan.globals");

195 if (!Globals)

196 return;

197

199 FunctionType::get(Type::getVoidTy(M.getContext()), false),

204

205 const DataLayout &DL = M.getDataLayout();

206 Value *ShadowBase = getShadowBase(*TysanGlobalsSetTypeFunction);

207 Value *AppMemMask = getAppMemMask(*TysanGlobalsSetTypeFunction);

208 TypeDescriptorsMapTy TypeDescriptors;

209 TypeNameMapTy TypeNames;

210

211 for (const auto &GMD : Globals->operands()) {

213 if (!GV)

214 continue;

215 const MDNode *TBAAMD = cast(GMD->getOperand(1));

216 if (!generateBaseTypeDescriptor(TBAAMD, TypeDescriptors, TypeNames, M))

217 continue;

218

221 Type *AccessTy = GV->getValueType();

223 uint64_t AccessSize = DL.getTypeStoreSize(AccessTy);

224 instrumentWithShadowUpdate(IRB, TBAAMD, GV, AccessSize, false, false,

225 ShadowBase, AppMemMask, true, false,

226 TypeDescriptors, DL);

227 }

228

229 if (TysanGlobalsSetTypeFunction) {

231 ->getEntryBlock()

232 .getTerminator());

233 IRB.CreateCall(TysanGlobalsSetTypeFunction, {});

234 }

235}

236

237static const char LUT[] = "0123456789abcdef";

238

240 size_t Length = Name.size();

242 Output.reserve(Output.size() + 3 * Length);

243 for (size_t i = 0; i < Length; ++i) {

244 const unsigned char c = Name[i];

245 if (isalnum(c)) {

246 Output.push_back(c);

247 continue;

248 }

249

250 if (c == '_') {

251 Output.append("__");

252 continue;

253 }

254

255 Output.push_back('_');

256 Output.push_back(LUT[c >> 4]);

257 Output.push_back(LUT[c & 15]);

258 }

259

260 return Output;

261}

262

263std::string

264TypeSanitizer::getAnonymousStructIdentifier(const MDNode *MD,

265 TypeNameMapTy &TypeNames) {

266 MD5 Hash;

267

268 for (int i = 1, e = MD->getNumOperands(); i < e; i += 2) {

270 if (!MemberNode)

271 return "";

272

273 auto TNI = TypeNames.find(MemberNode);

274 std::string MemberName;

275 if (TNI != TypeNames.end()) {

276 MemberName = TNI->second;

277 } else {

279 return "";

281 if (!MemberNameNode)

282 return "";

283 MemberName = MemberNameNode->getString().str();

284 if (MemberName.empty())

285 MemberName = getAnonymousStructIdentifier(MemberNode, TypeNames);

286 if (MemberName.empty())

287 return "";

288 TypeNames[MemberNode] = MemberName;

289 }

290

291 Hash.update(MemberName);

293

298 }

299

300 MD5::MD5Result HashResult;

301 Hash.final(HashResult);

302 return "__anonymous_" + std::string(HashResult.digest().str());

303}

304

305bool TypeSanitizer::generateBaseTypeDescriptor(

306 const MDNode *MD, TypeDescriptorsMapTy &TypeDescriptors,

307 TypeNameMapTy &TypeNames, Module &M) {

309 return false;

310

312 if (!NameNode)

313 return false;

314

316 if (Name.empty())

317 Name = getAnonymousStructIdentifier(MD, TypeNames);

318 if (Name.empty())

319 return false;

320 TypeNames[MD] = Name;

321 std::string EncodedName = encodeName(Name);

322

323 GlobalVariable *GV =

325 if (GV) {

326 TypeDescriptors[MD] = GV;

327 return true;

328 }

329

331 for (int i = 1, e = MD->getNumOperands(); i < e; i += 2) {

333 if (!MemberNode)

334 return false;

335

337 auto TDI = TypeDescriptors.find(MemberNode);

338 if (TDI != TypeDescriptors.end()) {

339 Member = TDI->second;

340 } else {

341 if (!generateBaseTypeDescriptor(MemberNode, TypeDescriptors, TypeNames,

342 M))

343 return false;

344

345 Member = TypeDescriptors[MemberNode];

346 }

347

350

352 }

353

354

355

356

361

362 auto PushTDSub = [&](Constant *C) {

365 };

366

367 PushTDSub(ConstantInt::get(IntptrTy, 2));

368 PushTDSub(ConstantInt::get(IntptrTy, Members.size()));

369

370

371

372

373

374

375

376 bool ShouldBeComdat = !AnonNameRegex.match(NameNode->getString());

377 for (auto &Member : Members) {

378 PushTDSub(Member.first);

379 PushTDSub(ConstantInt::get(IntptrTy, Member.second));

380 }

381

382 PushTDSub(NameData);

383

386

387 GlobalVariable *TDGV =

388 new GlobalVariable(TDTy, true,

391 TD, EncodedName);

392 M.insertGlobalVariable(TDGV);

393

394 if (ShouldBeComdat) {

396 Comdat *TDComdat = M.getOrInsertComdat(EncodedName);

398 }

400 }

401

402 TypeDescriptors[MD] = TDGV;

403 return true;

404}

405

406bool TypeSanitizer::generateTypeDescriptor(

407 const MDNode *MD, TypeDescriptorsMapTy &TypeDescriptors,

408 TypeNameMapTy &TypeNames, Module &M) {

409

410

411

412

414 return false;

415

417 if (!BaseNode)

418 return false;

419

420

421

423 if (!AccessNode)

424 return false;

425

427 auto TDI = TypeDescriptors.find(BaseNode);

428 if (TDI != TypeDescriptors.end()) {

429 Base = TDI->second;

430 } else {

431 if (!generateBaseTypeDescriptor(BaseNode, TypeDescriptors, TypeNames, M))

432 return false;

433

434 Base = TypeDescriptors[BaseNode];

435 }

436

438 TDI = TypeDescriptors.find(AccessNode);

439 if (TDI != TypeDescriptors.end()) {

440 Access = TDI->second;

441 } else {

442 if (!generateBaseTypeDescriptor(AccessNode, TypeDescriptors, TypeNames, M))

443 return false;

444

445 Access = TypeDescriptors[AccessNode];

446 }

447

450 std::string EncodedName =

452

453 GlobalVariable *GV =

455 if (GV) {

456 TypeDescriptors[MD] = GV;

457 return true;

458 }

459

460

461

462

463 StructType *TDTy =

467 ConstantInt::get(IntptrTy, Offset));

468

471

472 GlobalVariable *TDGV =

473 new GlobalVariable(TDTy, true,

476 TD, EncodedName);

477 M.insertGlobalVariable(TDGV);

478

479 if (ShouldBeComdat) {

481 Comdat *TDComdat = M.getOrInsertComdat(EncodedName);

483 }

485 }

486

487 TypeDescriptors[MD] = TDGV;

488 return true;

489}

490

491Instruction *TypeSanitizer::getShadowBase(Function &F) {

493 Constant *GlobalShadowAddress =

495 return IRB.CreateLoad(IntptrTy, GlobalShadowAddress, "shadow.base");

496}

497

498Instruction *TypeSanitizer::getAppMemMask(Function &F) {

500 Value *GlobalAppMemMask =

502 return IRB.CreateLoad(IntptrTy, GlobalAppMemMask, "app.mem.mask");

503}

504

505

506

509 SmallVectorImpl<std::pair<Instruction *, MemoryLocation>> &MemoryAccesses,

512

514

515 if (Inst.getMetadata(LLVMContext::MD_nosanitize))

516 continue;

517

521

522

524 continue;

525

526

529 continue;

530

533 MemoryAccesses.push_back(std::make_pair(&Inst, MLoc));

537

539 MemTypeResetInsts.push_back(&Inst);

541 MemTypeResetInsts.push_back(&Inst);

542 }

543 }

544}

545

546bool TypeSanitizer::sanitizeFunction(Function &F,

547 const TargetLibraryInfo &TLI) {

548 if (F.isDeclaration())

549 return false;

550

551

552 if (&F == TysanCtorFunction.getCallee() || &F == TysanGlobalsSetTypeFunction)

553 return false;

554 initializeCallbacks(*F.getParent());

555

556

557

559 SmallSetVector<const MDNode *, 8> TBAAMetadata;

562

563

564

565 for (auto &A : F.args())

566 if (A.hasByValAttr())

568

570 TypeDescriptorsMapTy TypeDescriptors;

571 TypeNameMapTy TypeNames;

572 bool Res = false;

573 for (const MDNode *MD : TBAAMetadata) {

574 if (TypeDescriptors.count(MD))

575 continue;

576

577 if (!generateTypeDescriptor(MD, TypeDescriptors, TypeNames, M))

578 return Res;

579

580 Res = true;

581 }

582

584 bool SanitizeFunction = F.hasFnAttribute(Attribute::SanitizeType);

585 bool NeedsInstrumentation =

586 MemTypeResetInsts.empty() && MemoryAccesses.empty();

587 Instruction *ShadowBase = NeedsInstrumentation ? nullptr : getShadowBase(F);

588 Instruction *AppMemMask = NeedsInstrumentation ? nullptr : getAppMemMask(F);

589 for (const auto &[I, MLoc] : MemoryAccesses) {

591 assert(MLoc.Size.isPrecise());

592 if (instrumentWithShadowUpdate(

593 IRB, MLoc.AATags.TBAA, const_cast<Value *>(MLoc.Ptr),

594 MLoc.Size.getValue(), I->mayReadFromMemory(), I->mayWriteToMemory(),

595 ShadowBase, AppMemMask, false, SanitizeFunction, TypeDescriptors,

596 DL)) {

597 ++NumInstrumentedAccesses;

598 Res = true;

599 }

600 }

601

602 for (auto Inst : MemTypeResetInsts)

603 Res |= instrumentMemInst(Inst, ShadowBase, AppMemMask, DL);

604

605 return Res;

606}

607

610 Value *ShadowBase, Value *AppMemMask) {

614 AppMemMask, "app.ptr.masked"),

615 PtrShift, "app.ptr.shifted"),

616 ShadowBase, "shadow.ptr.int");

617}

618

619bool TypeSanitizer::instrumentWithShadowUpdate(

620 IRBuilder<> &IRB, const MDNode *TBAAMD, Value *Ptr, uint64_t AccessSize,

621 bool IsRead, bool IsWrite, Value *ShadowBase, Value *AppMemMask,

622 bool ForceSetType, bool SanitizeFunction,

623 TypeDescriptorsMapTy &TypeDescriptors, const DataLayout &DL) {

625 if (TBAAMD)

626 TDGV = TypeDescriptors[TBAAMD];

627 else

629

631

634

635

636

637

638

640 ConstantInt::get(OrdTy, (int)IsRead | (((int)IsWrite) << 1));

641

642 IRB.CreateCall(TysanInstrumentWithShadowUpdate,

643 {Ptr, TD,

646 } else if (ForceSetType || IsWrite) {

647

648

649 IRB.CreateCall(TysanSetShadowType, {Ptr, TD, IRB.getInt64(AccessSize)});

650 }

651

652 return true;

653 }

654

656 ShadowBase, AppMemMask);

657 Type *Int8PtrPtrTy = PointerType::get(IRB.getContext(), 0);

658 Value *ShadowData =

659 IRB.CreateIntToPtr(ShadowDataInt, Int8PtrPtrTy, "shadow.ptr");

660

661 auto SetType = [&]() {

663

664

665

666 for (uint64_t i = 1; i < AccessSize; ++i) {

669 ConstantInt::get(IntptrTy, i << PtrShift),

670 "shadow.byte." + Twine(i) + ".offset"),

671 Int8PtrPtrTy, "shadow.byte." + Twine(i) + ".ptr");

672

673

674

677 IRB.getPtrTy(), "bad.descriptor" + Twine(i));

679 }

680 };

681

683

684

685 SetType();

686 return true;

687 }

688

690 "should have handled case above");

692 MDNode *UnlikelyBW = MDBuilder(C).createBranchWeights(1, 100000);

693

694 if (!SanitizeFunction) {

695

696

700 NullTDCmp, &*IRB.GetInsertPoint(), false, UnlikelyBW);

702 NullTDTerm->getParent()->setName("set.type");

703 SetType();

704 return true;

705 }

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761 Constant *Flags = ConstantInt::get(OrdTy, int(IsRead) | (int(IsWrite) << 1));

762

767 &GoodTDTerm, UnlikelyBW);

769

770

771

775 &MismatchTerm);

776

777

779

780

781

782 Value *Size = ConstantInt::get(OrdTy, AccessSize);

784 for (uint64_t i = 1; i < AccessSize; ++i) {

786 IRB.CreateAdd(ShadowDataInt, ConstantInt::get(IntptrTy, i << PtrShift)),

787 Int8PtrPtrTy);

790 }

791

798

800 SetType();

801

802

806

807

808

811 for (uint64_t i = 1; i < AccessSize; ++i) {

813 IRB.CreateAdd(ShadowDataInt, ConstantInt::get(IntptrTy, i << PtrShift)),

814 Int8PtrPtrTy);

818 NotAllBadTD, IRB.CreateICmpSGE(ILdTD, ConstantInt::get(IntptrTy, 0)));

819 }

820

822 NotAllBadTD, &*IRB.GetInsertPoint(), false, UnlikelyBW);

826 return true;

827}

828

829bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,

830 Instruction *AppMemMask,

831 const DataLayout &DL) {

835

840 } else {

842 F = A->getParent();

843 BB = &F->getEntryBlock();

845

846

847 if (IP->comesBefore(ShadowBase))

849 if (IP->comesBefore(AppMemMask))

851 }

852

853 Value *Dest, *Size, *Src = nullptr;

854 bool NeedsMemMove = false;

856

857 auto GetAllocaSize = [&](AllocaInst *AI) {

860 ConstantInt::get(IntptrTy,

861 DL.getTypeAllocSize(AI->getAllocatedType())));

862 };

863

865 assert(A->hasByValAttr() && "Type reset for non-byval argument?");

866

867 Dest = A;

869 ConstantInt::get(IntptrTy, DL.getTypeAllocSize(A->getParamByValType()));

870 } else {

873 if (MI->getDestAddressSpace() != 0)

874 return false;

875

876 Dest = MI->getDest();

877 Size = MI->getLength();

878

880 if (MTI->getSourceAddressSpace() == 0) {

881 Src = MTI->getSource();

883 }

884 }

887 if (!AI)

888 return false;

889

890 Size = GetAllocaSize(AI);

891 Dest = II->getArgOperand(0);

893

894

895

898

899 Size = GetAllocaSize(AI);

900 Dest = I;

901 } else {

902 return false;

903 }

904 }

905

907 if (!Src)

909

911 TysanIntrumentMemInst,

913 return true;

914 } else {

915 if (!ShadowBase)

916 ShadowBase = getShadowBase(*F);

917 if (!AppMemMask)

918 AppMemMask = getAppMemMask(*F);

919

923 PtrShift),

924 ShadowBase);

926

927 if (!Src) {

930 return true;

931 }

932

936 PtrShift),

937 ShadowBase);

939

940 if (NeedsMemMove) {

941 IRB.CreateMemMove(ShadowData, Align(1ull << PtrShift), SrcShadowData,

943 } else {

944 IRB.CreateMemCpy(ShadowData, Align(1ull << PtrShift), SrcShadowData,

946 }

947 }

948

949 return true;

950}

951

955 std::tie(TysanCtorFunction, std::ignore) =

958 {});

959

960 TypeSanitizer TySan(M);

961 TySan.instrumentGlobals(M);

963

967 TySan.sanitizeFunction(F, TLI);

969

970

971

972

973

975 TySan.sanitizeFunction(F, TLI);

977 }

978 }

979

981}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Expand Atomic instructions

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

Module.h This file contains the declarations for the Module class.

Machine Check Debug Module

This file provides utility analysis objects describing memory locations.

uint64_t IntrinsicInst * II

FunctionAnalysisManager FAM

ModuleAnalysisManager MAM

This file implements a set that has insertion order iteration characteristics.

This file defines the SmallVector class.

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

static const char *const kTysanInitName

Definition TypeSanitizer.cpp:48

static Value * convertToShadowDataInt(IRBuilder<> &IRB, Value *Ptr, Type *IntptrTy, uint64_t PtrShift, Value *ShadowBase, Value *AppMemMask)

Definition TypeSanitizer.cpp:608

static const char *const kTysanShadowMemoryAddress

Definition TypeSanitizer.cpp:52

static const char LUT[]

Definition TypeSanitizer.cpp:237

static cl::opt< bool > ClOutlineInstrumentation("tysan-outline-instrumentation", cl::desc("Uses function calls for all TySan instrumentation, reducing " "ELF size"), cl::Hidden, cl::init(true))

static const char *const kTysanGVNamePrefix

Definition TypeSanitizer.cpp:50

static const char *const kTysanModuleCtorName

Definition TypeSanitizer.cpp:47

static const char *const kTysanAppMemMask

Definition TypeSanitizer.cpp:54

void collectMemAccessInfo(Function &F, const TargetLibraryInfo &TLI, SmallVectorImpl< std::pair< Instruction *, MemoryLocation > > &MemoryAccesses, SmallSetVector< const MDNode *, 8 > &TBAAMetadata, SmallVectorImpl< Value * > &MemTypeResetInsts)

Collect all loads and stores, and for what TBAA nodes we need to generate type descriptors.

Definition TypeSanitizer.cpp:507

static cl::opt< bool > ClVerifyOutlinedInstrumentation("tysan-verify-outlined-instrumentation", cl::desc("Check types twice with both inlined instrumentation and " "function calls. This verifies that they behave the same."), cl::Hidden, cl::init(false))

static cl::opt< bool > ClWritesAlwaysSetType("tysan-writes-always-set-type", cl::desc("Writes always set the type"), cl::Hidden, cl::init(false))

static const char *const kTysanCheckName

Definition TypeSanitizer.cpp:49

static std::string encodeName(StringRef Name)

Definition TypeSanitizer.cpp:239

LLVM_ABI const_iterator getFirstInsertionPt() const

Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...

const Function * getParent() const

Return the enclosing method, or null if none.

static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)

Creates a new BasicBlock.

InstListType::iterator iterator

Instruction iterators...

const Instruction * getTerminator() const LLVM_READONLY

Returns the terminator instruction if the block is well formed or null if the block is not well forme...

This class represents a function call, abstracting a target machine's calling convention.

static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)

This method constructs a CDS and initializes it with a text string.

static ConstantInt * getSigned(IntegerType *Ty, int64_t V)

Return a ConstantInt with the specified value for the specified type.

static LLVM_ABI ConstantPointerNull * get(PointerType *T)

Static factory methods - Return objects of the specified value.

static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)

static LLVM_ABI Constant * getNullValue(Type *Ty)

Constructor to create a '0' constant of arbitrary type.

A parsed version of the target data layout string in and methods for querying it.

A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...

static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)

const BasicBlock & getEntryBlock() const

LLVM_ABI void setComdat(Comdat *C)

@ InternalLinkage

Rename collisions when linking (static functions).

@ LinkOnceODRLinkage

Same, but only replaced by something equivalent.

Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")

Create a ZExt or Trunc from the integer value V to DestTy.

CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())

Create and insert a memcpy between the specified pointers.

ConstantInt * getTrue()

Get the constant value for i1 true.

Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")

BasicBlock::iterator GetInsertPoint() const

Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")

ConstantInt * getInt8(uint8_t C)

Get a constant 8-bit value.

Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")

ConstantInt * getInt64(uint64_t C)

Get a constant 64-bit value.

CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())

Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")

LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)

Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...

Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)

CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())

Create and insert a memset to the specified pointer and the specified value.

LLVMContext & getContext() const

Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")

StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)

Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)

Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")

ConstantInt * getFalse()

Get the constant value for i1 false.

Value * CreateIsNotNull(Value *Arg, const Twine &Name="")

Return a boolean value testing if Arg != 0.

CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)

PointerType * getPtrTy(unsigned AddrSpace=0)

Fetch the type representing a pointer.

Value * CreateIsNull(Value *Arg, const Twine &Name="")

Return a boolean value testing if Arg == 0.

void SetInsertPoint(BasicBlock *TheBB)

This specifies that created instructions should be appended to the end of the specified block.

LLVM_ABI void SetInstDebugLocation(Instruction *I) const

If this builder has a current debug location, set it on the specified instruction.

Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)

Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)

This provides a uniform API for creating instructions and inserting them into a basic block: either a...

Class to represent integer types.

LLVM_ABI void update(ArrayRef< uint8_t > Data)

Updates the hash for the byte stream provided.

LLVM_ABI void final(MD5Result &Result)

Finishes off the hash and puts the result in result.

const MDOperand & getOperand(unsigned I) const

unsigned getNumOperands() const

Return number of MDNode operands.

LLVMContext & getContext() const

LLVM_ABI StringRef getString() const

const MachineFunction * getParent() const

Return the MachineFunction containing this basic block.

const DataLayout & getDataLayout() const

Return the DataLayout attached to the Module associated to this MF.

Representation for a specific memory location.

static LLVM_ABI MemoryLocation get(const LoadInst *LI)

Return a location with information about the memory reference by the given instruction.

AAMDNodes AATags

The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...

const Value * Ptr

The address of the start of the location.

A Module instance is used to store all the information related to an LLVM module.

iterator_range< op_iterator > operands()

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses none()

Convenience factory function for the empty preserved set.

LLVM_ABI bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const

matches - Match the regex against a given String.

static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)

bool insert(const value_type &X)

Insert a new element into the SetVector.

A SetVector that performs no allocations if smaller than a certain size.

StringRef str() const

Explicit conversion to StringRef.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

StringRef - Represent a constant reference to a string, i.e.

std::string str() const

str - Get the contents as an std::string.

static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)

This static method is the primary way to create a literal StructType.

Analysis pass providing the TargetLibraryInfo.

Provides information about what library functions are available for the current target.

Triple - Helper class for working with autoconf configuration names.

bool isOSBinFormatELF() const

Tests whether the OS uses the ELF binary format.

The instances of the Type class are immutable: once they are created, they are never changed.

static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)

static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)

LLVM_ABI unsigned getPointerAddressSpace() const

Get the address space of this pointer or pointer vector type.

bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const

Return true if it makes sense to take the size of this type.

static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)

LLVM Value Representation.

Type * getType() const

All values are typed, get the type of this value.

LLVM_ABI bool isSwiftError() const

Return true if this value is a swifterror value.

const ParentTy * getParent() const

self_iterator getIterator()

NodeTy * getNextNode()

Get the next node, or nullptr for the list tail.

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

@ C

The default llvm calling convention, compatible with C.

@ BasicBlock

Various leaf nodes.

initializer< Ty > init(const Ty &Val)

std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)

Extract a Value from Metadata, if any, allowing null.

std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)

Extract a Value from Metadata.

friend class Instruction

Iterator for Instructions in a `BasicBlock.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy

Provide the FunctionAnalysisManager to Module proxy.

std::string utostr(uint64_t X, bool isNeg=false)

int countr_zero(T Val)

Count number of 0's from the least significant bit to the most stopping at the first 1.

auto dyn_cast_or_null(const Y &Val)

LLVM_ABI std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef(), bool Weak=false)

Creates sanitizer constructor function, and calls sanitizer's init function from it.

LLVM_ABI void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)

SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >

LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)

Append F to the list of global ctors of module M with the given Priority.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)

Split the containing block at the specified instruction - everything before SplitBefore stays in the ...

LLVM_ABI void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, const TargetLibraryInfo *TLI)

Given a CallInst, check if it calls a string function known to CodeGen, and mark it with NoBuiltin if...

LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)

Adds global values to the llvm.used list.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

MDNode * TBAA

The tag for type-based alias analysis.

LLVM_ABI SmallString< 32 > digest() const

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)

Definition TypeSanitizer.cpp:952