LLVM 22.0.0git
TypeSanitizer.cpp
Go to the documentation of this file.
1//===----- TypeSanitizer.cpp - type-based-aliasing-violation detector -----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of TypeSanitizer, a type-based-aliasing-violation
10// detector.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/SetVector.h"
17#include "llvm/ADT/Statistic.h"
21#include "llvm/IR/DataLayout.h"
22#include "llvm/IR/Function.h"
23#include "llvm/IR/IRBuilder.h"
27#include "llvm/IR/Intrinsics.h"
28#include "llvm/IR/LLVMContext.h"
29#include "llvm/IR/MDBuilder.h"
30#include "llvm/IR/Metadata.h"
31#include "llvm/IR/Module.h"
32#include "llvm/IR/Type.h"
35#include "llvm/Support/MD5.h"
36#include "llvm/Support/Regex.h"
40
41#include <cctype>
42
43using namespace llvm;
44
45#define DEBUG_TYPE "tysan"
46
47static const char *const kTysanModuleCtorName = "tysan.module_ctor";
48static const char *const kTysanInitName = "__tysan_init";
49static const char *const kTysanCheckName = "__tysan_check";
50static const char *const kTysanGVNamePrefix = "__tysan_v1_";
51
52static const char *const kTysanShadowMemoryAddress =
53 "__tysan_shadow_memory_address";
54static const char *const kTysanAppMemMask = "__tysan_app_memory_mask";
55
56static cl::opt<bool>
57 ClWritesAlwaysSetType("tysan-writes-always-set-type",
58 cl::desc("Writes always set the type"), cl::Hidden,
59 cl::init(false));
60
61STATISTIC(NumInstrumentedAccesses, "Number of instrumented accesses");
62
63namespace {
64
65/// TypeSanitizer: instrument the code in module to find type-based aliasing
66/// violations.
67struct TypeSanitizer {
68 TypeSanitizer(Module &M);
69 bool sanitizeFunction(Function &F, const TargetLibraryInfo &TLI);
70 void instrumentGlobals(Module &M);
71
72private:
74 TypeDescriptorsMapTy;
76
77 void initializeCallbacks(Module &M);
78
79 Instruction *getShadowBase(Function &F);
80 Instruction *getAppMemMask(Function &F);
81
82 bool instrumentWithShadowUpdate(IRBuilder<> &IRB, const MDNode *TBAAMD,
83 Value *Ptr, uint64_t AccessSize, bool IsRead,
84 bool IsWrite, Value *ShadowBase,
85 Value *AppMemMask, bool ForceSetType,
86 bool SanitizeFunction,
87 TypeDescriptorsMapTy &TypeDescriptors,
88 const DataLayout &DL);
89
90 /// Memory-related intrinsics/instructions reset the type of the destination
91 /// memory (including allocas and byval arguments).
92 bool instrumentMemInst(Value *I, Instruction *ShadowBase,
93 Instruction *AppMemMask, const DataLayout &DL);
94
95 std::string getAnonymousStructIdentifier(const MDNode *MD,
96 TypeNameMapTy &TypeNames);
97 bool generateTypeDescriptor(const MDNode *MD,
98 TypeDescriptorsMapTy &TypeDescriptors,
99 TypeNameMapTy &TypeNames, Module &M);
100 bool generateBaseTypeDescriptor(const MDNode *MD,
101 TypeDescriptorsMapTy &TypeDescriptors,
102 TypeNameMapTy &TypeNames, Module &M);
103
104 const Triple TargetTriple;
105 Regex AnonNameRegex;
106 Type *IntptrTy;
107 uint64_t PtrShift;
108 IntegerType *OrdTy;
109
110 /// Callbacks to run-time library are computed in initializeCallbacks.
111 FunctionCallee TysanCheck;
112 FunctionCallee TysanCtorFunction;
113
114 /// Callback to set types for gloabls.
115 Function *TysanGlobalsSetTypeFunction;
116};
117} // namespace
118
119TypeSanitizer::TypeSanitizer(Module &M)
120 : TargetTriple(M.getTargetTriple()),
121 AnonNameRegex("^_ZTS.*N[1-9][0-9]*_GLOBAL__N") {
122 const DataLayout &DL = M.getDataLayout();
123 IntptrTy = DL.getIntPtrType(M.getContext());
124 PtrShift = countr_zero(IntptrTy->getPrimitiveSizeInBits() / 8);
125
126 TysanGlobalsSetTypeFunction = M.getFunction("__tysan_set_globals_types");
127 initializeCallbacks(M);
128}
129
130void TypeSanitizer::initializeCallbacks(Module &M) {
131 IRBuilder<> IRB(M.getContext());
132 OrdTy = IRB.getInt32Ty();
133
134 AttributeList Attr;
135 Attr = Attr.addFnAttribute(M.getContext(), Attribute::NoUnwind);
136 // Initialize the callbacks.
137 TysanCheck =
138 M.getOrInsertFunction(kTysanCheckName, Attr, IRB.getVoidTy(),
139 IRB.getPtrTy(), // Pointer to data to be read.
140 OrdTy, // Size of the data in bytes.
141 IRB.getPtrTy(), // Pointer to type descriptor.
142 OrdTy // Flags.
143 );
144
145 TysanCtorFunction =
146 M.getOrInsertFunction(kTysanModuleCtorName, Attr, IRB.getVoidTy());
147}
148
149void TypeSanitizer::instrumentGlobals(Module &M) {
150 TysanGlobalsSetTypeFunction = nullptr;
151
152 NamedMDNode *Globals = M.getNamedMetadata("llvm.tysan.globals");
153 if (!Globals)
154 return;
155
156 TysanGlobalsSetTypeFunction = Function::Create(
157 FunctionType::get(Type::getVoidTy(M.getContext()), false),
158 GlobalValue::InternalLinkage, "__tysan_set_globals_types", &M);
159 BasicBlock *BB =
160 BasicBlock::Create(M.getContext(), "", TysanGlobalsSetTypeFunction);
161 ReturnInst::Create(M.getContext(), BB);
162
163 const DataLayout &DL = M.getDataLayout();
164 Value *ShadowBase = getShadowBase(*TysanGlobalsSetTypeFunction);
165 Value *AppMemMask = getAppMemMask(*TysanGlobalsSetTypeFunction);
166 TypeDescriptorsMapTy TypeDescriptors;
167 TypeNameMapTy TypeNames;
168
169 for (const auto &GMD : Globals->operands()) {
170 auto *GV = mdconst::dyn_extract_or_null<GlobalVariable>(GMD->getOperand(0));
171 if (!GV)
172 continue;
173 const MDNode *TBAAMD = cast<MDNode>(GMD->getOperand(1));
174 if (!generateBaseTypeDescriptor(TBAAMD, TypeDescriptors, TypeNames, M))
175 continue;
176
177 IRBuilder<> IRB(
178 TysanGlobalsSetTypeFunction->getEntryBlock().getTerminator());
179 Type *AccessTy = GV->getValueType();
180 assert(AccessTy->isSized());
181 uint64_t AccessSize = DL.getTypeStoreSize(AccessTy);
182 instrumentWithShadowUpdate(IRB, TBAAMD, GV, AccessSize, false, false,
183 ShadowBase, AppMemMask, true, false,
184 TypeDescriptors, DL);
185 }
186
187 if (TysanGlobalsSetTypeFunction) {
188 IRBuilder<> IRB(cast<Function>(TysanCtorFunction.getCallee())
189 ->getEntryBlock()
190 .getTerminator());
191 IRB.CreateCall(TysanGlobalsSetTypeFunction, {});
192 }
193}
194
195static const char LUT[] = "0123456789abcdef";
196
197static std::string encodeName(StringRef Name) {
198 size_t Length = Name.size();
199 std::string Output = kTysanGVNamePrefix;
200 Output.reserve(Output.size() + 3 * Length);
201 for (size_t i = 0; i < Length; ++i) {
202 const unsigned char c = Name[i];
203 if (isalnum(c)) {
204 Output.push_back(c);
205 continue;
206 }
207
208 if (c == '_') {
209 Output.append("__");
210 continue;
211 }
212
213 Output.push_back('_');
214 Output.push_back(LUT[c >> 4]);
215 Output.push_back(LUT[c & 15]);
216 }
217
218 return Output;
219}
220
221std::string
222TypeSanitizer::getAnonymousStructIdentifier(const MDNode *MD,
223 TypeNameMapTy &TypeNames) {
224 MD5 Hash;
225
226 for (int i = 1, e = MD->getNumOperands(); i < e; i += 2) {
227 const MDNode *MemberNode = dyn_cast<MDNode>(MD->getOperand(i));
228 if (!MemberNode)
229 return "";
230
231 auto TNI = TypeNames.find(MemberNode);
232 std::string MemberName;
233 if (TNI != TypeNames.end()) {
234 MemberName = TNI->second;
235 } else {
236 if (MemberNode->getNumOperands() < 1)
237 return "";
238 MDString *MemberNameNode = dyn_cast<MDString>(MemberNode->getOperand(0));
239 if (!MemberNameNode)
240 return "";
241 MemberName = MemberNameNode->getString().str();
242 if (MemberName.empty())
243 MemberName = getAnonymousStructIdentifier(MemberNode, TypeNames);
244 if (MemberName.empty())
245 return "";
246 TypeNames[MemberNode] = MemberName;
247 }
248
249 Hash.update(MemberName);
250 Hash.update("\0");
251
253 mdconst::extract<ConstantInt>(MD->getOperand(i + 1))->getZExtValue();
254 Hash.update(utostr(Offset));
255 Hash.update("\0");
256 }
257
258 MD5::MD5Result HashResult;
259 Hash.final(HashResult);
260 return "__anonymous_" + std::string(HashResult.digest().str());
261}
262
263bool TypeSanitizer::generateBaseTypeDescriptor(
264 const MDNode *MD, TypeDescriptorsMapTy &TypeDescriptors,
265 TypeNameMapTy &TypeNames, Module &M) {
266 if (MD->getNumOperands() < 1)
267 return false;
268
269 MDString *NameNode = dyn_cast<MDString>(MD->getOperand(0));
270 if (!NameNode)
271 return false;
272
273 std::string Name = NameNode->getString().str();
274 if (Name.empty())
275 Name = getAnonymousStructIdentifier(MD, TypeNames);
276 if (Name.empty())
277 return false;
278 TypeNames[MD] = Name;
279 std::string EncodedName = encodeName(Name);
280
281 GlobalVariable *GV =
282 dyn_cast_or_null<GlobalVariable>(M.getNamedValue(EncodedName));
283 if (GV) {
284 TypeDescriptors[MD] = GV;
285 return true;
286 }
287
289 for (int i = 1, e = MD->getNumOperands(); i < e; i += 2) {
290 const MDNode *MemberNode = dyn_cast<MDNode>(MD->getOperand(i));
291 if (!MemberNode)
292 return false;
293
295 auto TDI = TypeDescriptors.find(MemberNode);
296 if (TDI != TypeDescriptors.end()) {
297 Member = TDI->second;
298 } else {
299 if (!generateBaseTypeDescriptor(MemberNode, TypeDescriptors, TypeNames,
300 M))
301 return false;
302
303 Member = TypeDescriptors[MemberNode];
304 }
305
307 mdconst::extract<ConstantInt>(MD->getOperand(i + 1))->getZExtValue();
308
309 Members.push_back(std::make_pair(Member, Offset));
310 }
311
312 // The descriptor for a scalar is:
313 // [2, member count, [type pointer, offset]..., name]
314
315 LLVMContext &C = MD->getContext();
316 Constant *NameData = ConstantDataArray::getString(C, NameNode->getString());
317 SmallVector<Type *> TDSubTys;
318 SmallVector<Constant *> TDSubData;
319
320 auto PushTDSub = [&](Constant *C) {
321 TDSubTys.push_back(C->getType());
322 TDSubData.push_back(C);
323 };
324
325 PushTDSub(ConstantInt::get(IntptrTy, 2));
326 PushTDSub(ConstantInt::get(IntptrTy, Members.size()));
327
328 // Types that are in an anonymous namespace are local to this module.
329 // FIXME: This should really be marked by the frontend in the metadata
330 // instead of having us guess this from the mangled name. Moreover, the regex
331 // here can pick up (unlikely) names in the non-reserved namespace (because
332 // it needs to search into the type to pick up cases where the type in the
333 // anonymous namespace is a template parameter, etc.).
334 bool ShouldBeComdat = !AnonNameRegex.match(NameNode->getString());
335 for (auto &Member : Members) {
336 PushTDSub(Member.first);
337 PushTDSub(ConstantInt::get(IntptrTy, Member.second));
338 }
339
340 PushTDSub(NameData);
341
342 StructType *TDTy = StructType::get(C, TDSubTys);
343 Constant *TD = ConstantStruct::get(TDTy, TDSubData);
344
345 GlobalVariable *TDGV =
346 new GlobalVariable(TDTy, true,
347 !ShouldBeComdat ? GlobalValue::InternalLinkage
349 TD, EncodedName);
350 M.insertGlobalVariable(TDGV);
351
352 if (ShouldBeComdat) {
353 if (TargetTriple.isOSBinFormatELF()) {
354 Comdat *TDComdat = M.getOrInsertComdat(EncodedName);
355 TDGV->setComdat(TDComdat);
356 }
357 appendToUsed(M, TDGV);
358 }
359
360 TypeDescriptors[MD] = TDGV;
361 return true;
362}
363
364bool TypeSanitizer::generateTypeDescriptor(
365 const MDNode *MD, TypeDescriptorsMapTy &TypeDescriptors,
366 TypeNameMapTy &TypeNames, Module &M) {
367 // Here we need to generate a type descriptor corresponding to this TBAA
368 // metadata node. Under the current scheme there are three kinds of TBAA
369 // metadata nodes: scalar nodes, struct nodes, and struct tag nodes.
370
371 if (MD->getNumOperands() < 3)
372 return false;
373
374 const MDNode *BaseNode = dyn_cast<MDNode>(MD->getOperand(0));
375 if (!BaseNode)
376 return false;
377
378 // This is a struct tag (element-access) node.
379
380 const MDNode *AccessNode = dyn_cast<MDNode>(MD->getOperand(1));
381 if (!AccessNode)
382 return false;
383
384 Constant *Base;
385 auto TDI = TypeDescriptors.find(BaseNode);
386 if (TDI != TypeDescriptors.end()) {
387 Base = TDI->second;
388 } else {
389 if (!generateBaseTypeDescriptor(BaseNode, TypeDescriptors, TypeNames, M))
390 return false;
391
392 Base = TypeDescriptors[BaseNode];
393 }
394
396 TDI = TypeDescriptors.find(AccessNode);
397 if (TDI != TypeDescriptors.end()) {
398 Access = TDI->second;
399 } else {
400 if (!generateBaseTypeDescriptor(AccessNode, TypeDescriptors, TypeNames, M))
401 return false;
402
403 Access = TypeDescriptors[AccessNode];
404 }
405
407 mdconst::extract<ConstantInt>(MD->getOperand(2))->getZExtValue();
408 std::string EncodedName =
409 std::string(Base->getName()) + "_o_" + utostr(Offset);
410
411 GlobalVariable *GV =
412 dyn_cast_or_null<GlobalVariable>(M.getNamedValue(EncodedName));
413 if (GV) {
414 TypeDescriptors[MD] = GV;
415 return true;
416 }
417
418 // The descriptor for a scalar is:
419 // [1, base-type pointer, access-type pointer, offset]
420
421 StructType *TDTy =
422 StructType::get(IntptrTy, Base->getType(), Access->getType(), IntptrTy);
423 Constant *TD =
424 ConstantStruct::get(TDTy, ConstantInt::get(IntptrTy, 1), Base, Access,
425 ConstantInt::get(IntptrTy, Offset));
426
427 bool ShouldBeComdat = cast<GlobalVariable>(Base)->getLinkage() ==
429
430 GlobalVariable *TDGV =
431 new GlobalVariable(TDTy, true,
432 !ShouldBeComdat ? GlobalValue::InternalLinkage
434 TD, EncodedName);
435 M.insertGlobalVariable(TDGV);
436
437 if (ShouldBeComdat) {
438 if (TargetTriple.isOSBinFormatELF()) {
439 Comdat *TDComdat = M.getOrInsertComdat(EncodedName);
440 TDGV->setComdat(TDComdat);
441 }
442 appendToUsed(M, TDGV);
443 }
444
445 TypeDescriptors[MD] = TDGV;
446 return true;
447}
448
449Instruction *TypeSanitizer::getShadowBase(Function &F) {
450 IRBuilder<> IRB(&F.front().front());
451 Constant *GlobalShadowAddress =
452 F.getParent()->getOrInsertGlobal(kTysanShadowMemoryAddress, IntptrTy);
453 return IRB.CreateLoad(IntptrTy, GlobalShadowAddress, "shadow.base");
454}
455
456Instruction *TypeSanitizer::getAppMemMask(Function &F) {
457 IRBuilder<> IRB(&F.front().front());
458 Value *GlobalAppMemMask =
459 F.getParent()->getOrInsertGlobal(kTysanAppMemMask, IntptrTy);
460 return IRB.CreateLoad(IntptrTy, GlobalAppMemMask, "app.mem.mask");
461}
462
463/// Collect all loads and stores, and for what TBAA nodes we need to generate
464/// type descriptors.
466 Function &F, const TargetLibraryInfo &TLI,
467 SmallVectorImpl<std::pair<Instruction *, MemoryLocation>> &MemoryAccesses,
469 SmallVectorImpl<Value *> &MemTypeResetInsts) {
470 // Traverse all instructions, collect loads/stores/returns, check for calls.
471 for (Instruction &Inst : instructions(F)) {
472 // Skip memory accesses inserted by another instrumentation.
473 if (Inst.getMetadata(LLVMContext::MD_nosanitize))
474 continue;
475
476 if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst) ||
477 isa<AtomicCmpXchgInst>(Inst) || isa<AtomicRMWInst>(Inst)) {
479
480 // Swift errors are special (we can't introduce extra uses on them).
481 if (MLoc.Ptr->isSwiftError())
482 continue;
483
484 // Skip non-address-space-0 pointers; we don't know how to handle them.
485 Type *PtrTy = cast<PointerType>(MLoc.Ptr->getType());
486 if (PtrTy->getPointerAddressSpace() != 0)
487 continue;
488
489 if (MLoc.AATags.TBAA)
490 TBAAMetadata.insert(MLoc.AATags.TBAA);
491 MemoryAccesses.push_back(std::make_pair(&Inst, MLoc));
492 } else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
493 if (CallInst *CI = dyn_cast<CallInst>(&Inst))
495
496 if (isa<MemIntrinsic, LifetimeIntrinsic>(Inst))
497 MemTypeResetInsts.push_back(&Inst);
498 } else if (isa<AllocaInst>(Inst)) {
499 MemTypeResetInsts.push_back(&Inst);
500 }
501 }
502}
503
504bool TypeSanitizer::sanitizeFunction(Function &F,
505 const TargetLibraryInfo &TLI) {
506 if (F.isDeclaration())
507 return false;
508 // This is required to prevent instrumenting call to __tysan_init from within
509 // the module constructor.
510 if (&F == TysanCtorFunction.getCallee() || &F == TysanGlobalsSetTypeFunction)
511 return false;
512 initializeCallbacks(*F.getParent());
513
514 // We need to collect all loads and stores, and know for what TBAA nodes we
515 // need to generate type descriptors.
518 SmallVector<Value *> MemTypeResetInsts;
519 collectMemAccessInfo(F, TLI, MemoryAccesses, TBAAMetadata, MemTypeResetInsts);
520
521 // byval arguments also need their types reset (they're new stack memory,
522 // just like allocas).
523 for (auto &A : F.args())
524 if (A.hasByValAttr())
525 MemTypeResetInsts.push_back(&A);
526
527 Module &M = *F.getParent();
528 TypeDescriptorsMapTy TypeDescriptors;
529 TypeNameMapTy TypeNames;
530 bool Res = false;
531 for (const MDNode *MD : TBAAMetadata) {
532 if (TypeDescriptors.count(MD))
533 continue;
534
535 if (!generateTypeDescriptor(MD, TypeDescriptors, TypeNames, M))
536 return Res; // Giving up.
537
538 Res = true;
539 }
540
541 const DataLayout &DL = F.getParent()->getDataLayout();
542 bool SanitizeFunction = F.hasFnAttribute(Attribute::SanitizeType);
543 bool NeedsInstrumentation =
544 MemTypeResetInsts.empty() && MemoryAccesses.empty();
545 Instruction *ShadowBase = NeedsInstrumentation ? nullptr : getShadowBase(F);
546 Instruction *AppMemMask = NeedsInstrumentation ? nullptr : getAppMemMask(F);
547 for (const auto &[I, MLoc] : MemoryAccesses) {
548 IRBuilder<> IRB(I);
549 assert(MLoc.Size.isPrecise());
550 if (instrumentWithShadowUpdate(
551 IRB, MLoc.AATags.TBAA, const_cast<Value *>(MLoc.Ptr),
552 MLoc.Size.getValue(), I->mayReadFromMemory(), I->mayWriteToMemory(),
553 ShadowBase, AppMemMask, false, SanitizeFunction, TypeDescriptors,
554 DL)) {
555 ++NumInstrumentedAccesses;
556 Res = true;
557 }
558 }
559
560 for (auto Inst : MemTypeResetInsts)
561 Res |= instrumentMemInst(Inst, ShadowBase, AppMemMask, DL);
562
563 return Res;
564}
565
567 Type *IntptrTy, uint64_t PtrShift,
568 Value *ShadowBase, Value *AppMemMask) {
569 return IRB.CreateAdd(
570 IRB.CreateShl(
571 IRB.CreateAnd(IRB.CreatePtrToInt(Ptr, IntptrTy, "app.ptr.int"),
572 AppMemMask, "app.ptr.masked"),
573 PtrShift, "app.ptr.shifted"),
574 ShadowBase, "shadow.ptr.int");
575}
576
577bool TypeSanitizer::instrumentWithShadowUpdate(
578 IRBuilder<> &IRB, const MDNode *TBAAMD, Value *Ptr, uint64_t AccessSize,
579 bool IsRead, bool IsWrite, Value *ShadowBase, Value *AppMemMask,
580 bool ForceSetType, bool SanitizeFunction,
581 TypeDescriptorsMapTy &TypeDescriptors, const DataLayout &DL) {
582 Constant *TDGV;
583 if (TBAAMD)
584 TDGV = TypeDescriptors[TBAAMD];
585 else
586 TDGV = Constant::getNullValue(IRB.getPtrTy());
587
588 Value *TD = IRB.CreateBitCast(TDGV, IRB.getPtrTy());
589
590 Value *ShadowDataInt = convertToShadowDataInt(IRB, Ptr, IntptrTy, PtrShift,
591 ShadowBase, AppMemMask);
592 Type *Int8PtrPtrTy = PointerType::get(IRB.getContext(), 0);
593 Value *ShadowData =
594 IRB.CreateIntToPtr(ShadowDataInt, Int8PtrPtrTy, "shadow.ptr");
595
596 auto SetType = [&]() {
597 IRB.CreateStore(TD, ShadowData);
598
599 // Now fill the remainder of the shadow memory corresponding to the
600 // remainder of the the bytes of the type with a bad type descriptor.
601 for (uint64_t i = 1; i < AccessSize; ++i) {
602 Value *BadShadowData = IRB.CreateIntToPtr(
603 IRB.CreateAdd(ShadowDataInt,
604 ConstantInt::get(IntptrTy, i << PtrShift),
605 "shadow.byte." + Twine(i) + ".offset"),
606 Int8PtrPtrTy, "shadow.byte." + Twine(i) + ".ptr");
607
608 // This is the TD value, -i, which is used to indicate that the byte is
609 // i bytes after the first byte of the type.
610 Value *BadTD =
611 IRB.CreateIntToPtr(ConstantInt::getSigned(IntptrTy, -i),
612 IRB.getPtrTy(), "bad.descriptor" + Twine(i));
613 IRB.CreateStore(BadTD, BadShadowData);
614 }
615 };
616
617 if (ForceSetType || (ClWritesAlwaysSetType && IsWrite)) {
618 // In the mode where writes always set the type, for a write (which does
619 // not also read), we just set the type.
620 SetType();
621 return true;
622 }
623
624 assert((!ClWritesAlwaysSetType || IsRead) &&
625 "should have handled case above");
626 LLVMContext &C = IRB.getContext();
627 MDNode *UnlikelyBW = MDBuilder(C).createBranchWeights(1, 100000);
628
629 if (!SanitizeFunction) {
630 // If we're not sanitizing this function, then we only care whether we
631 // need to *set* the type.
632 Value *LoadedTD = IRB.CreateLoad(IRB.getPtrTy(), ShadowData, "shadow.desc");
633 Value *NullTDCmp = IRB.CreateIsNull(LoadedTD, "desc.set");
635 NullTDCmp, &*IRB.GetInsertPoint(), false, UnlikelyBW);
636 IRB.SetInsertPoint(NullTDTerm);
637 NullTDTerm->getParent()->setName("set.type");
638 SetType();
639 return true;
640 }
641 // We need to check the type here. If the type is unknown, then the read
642 // sets the type. If the type is known, then it is checked. If the type
643 // doesn't match, then we call the runtime (which may yet determine that
644 // the mismatch is okay).
645 //
646 // The checks generated below have the following strucutre.
647 //
648 // ; First we load the descriptor for the load from shadow memory and
649 // ; compare it against the type descriptor for the current access type.
650 // %shadow.desc = load ptr %shadow.data
651 // %bad.desc = icmp ne %shadow.desc, %td
652 // br %bad.desc, %bad.bb, %good.bb
653 //
654 // bad.bb:
655 // %shadow.desc.null = icmp eq %shadow.desc, null
656 // br %shadow.desc.null, %null.td.bb, %good.td.bb
657 //
658 // null.td.bb:
659 // ; The typ is unknown, set it if all bytes in the value are also unknown.
660 // ; To check, we load the shadow data for all bytes of the access. For the
661 // ; pseudo code below, assume an access of size 1.
662 // %shadow.data.int = add %shadow.data.int, 0
663 // %l = load (inttoptr %shadow.data.int)
664 // %is.not.null = icmp ne %l, null
665 // %not.all.unknown = %is.not.null
666 // br %no.all.unknown, before.set.type.bb
667 //
668 // before.set.type.bb:
669 // ; Call runtime to check mismatch.
670 // call void @__tysan_check()
671 // br %set.type.bb
672 //
673 // set.type.bb:
674 // ; Now fill the remainder of the shadow memory corresponding to the
675 // ; remainder of the the bytes of the type with a bad type descriptor.
676 // store %TD, %shadow.data
677 // br %continue.bb
678 //
679 // good.td.bb::
680 // ; We have a non-trivial mismatch. Call the runtime.
681 // call void @__tysan_check()
682 // br %continue.bb
683 //
684 // good.bb:
685 // ; We appear to have the right type. Make sure that all other bytes in
686 // ; the type are still marked as interior bytes. If not, call the runtime.
687 // %shadow.data.int = add %shadow.data.int, 0
688 // %l = load (inttoptr %shadow.data.int)
689 // %not.all.interior = icmp sge %l, 0
690 // br %not.all.interior, label %check.rt.bb, label %continue.bb
691 //
692 // check.rt.bb:
693 // call void @__tysan_check()
694 // br %continue.bb
695
696 Constant *Flags = ConstantInt::get(OrdTy, int(IsRead) | (int(IsWrite) << 1));
697
698 Value *LoadedTD = IRB.CreateLoad(IRB.getPtrTy(), ShadowData, "shadow.desc");
699 Value *BadTDCmp = IRB.CreateICmpNE(LoadedTD, TD, "bad.desc");
700 Instruction *BadTDTerm, *GoodTDTerm;
701 SplitBlockAndInsertIfThenElse(BadTDCmp, &*IRB.GetInsertPoint(), &BadTDTerm,
702 &GoodTDTerm, UnlikelyBW);
703 IRB.SetInsertPoint(BadTDTerm);
704
705 // We now know that the types did not match (we're on the slow path). If
706 // the type is unknown, then set it.
707 Value *NullTDCmp = IRB.CreateIsNull(LoadedTD);
708 Instruction *NullTDTerm, *MismatchTerm;
709 SplitBlockAndInsertIfThenElse(NullTDCmp, &*IRB.GetInsertPoint(), &NullTDTerm,
710 &MismatchTerm);
711
712 // If the type is unknown, then set the type.
713 IRB.SetInsertPoint(NullTDTerm);
714
715 // We're about to set the type. Make sure that all bytes in the value are
716 // also of unknown type.
717 Value *Size = ConstantInt::get(OrdTy, AccessSize);
718 Value *NotAllUnkTD = IRB.getFalse();
719 for (uint64_t i = 1; i < AccessSize; ++i) {
720 Value *UnkShadowData = IRB.CreateIntToPtr(
721 IRB.CreateAdd(ShadowDataInt, ConstantInt::get(IntptrTy, i << PtrShift)),
722 Int8PtrPtrTy);
723 Value *ILdTD = IRB.CreateLoad(IRB.getPtrTy(), UnkShadowData);
724 NotAllUnkTD = IRB.CreateOr(NotAllUnkTD, IRB.CreateIsNotNull(ILdTD));
725 }
726
727 Instruction *BeforeSetType = &*IRB.GetInsertPoint();
728 Instruction *BadUTDTerm =
729 SplitBlockAndInsertIfThen(NotAllUnkTD, BeforeSetType, false, UnlikelyBW);
730 IRB.SetInsertPoint(BadUTDTerm);
731 IRB.CreateCall(TysanCheck, {IRB.CreateBitCast(Ptr, IRB.getPtrTy()), Size,
732 (Value *)TD, (Value *)Flags});
733
734 IRB.SetInsertPoint(BeforeSetType);
735 SetType();
736
737 // We have a non-trivial mismatch. Call the runtime.
738 IRB.SetInsertPoint(MismatchTerm);
739 IRB.CreateCall(TysanCheck, {IRB.CreateBitCast(Ptr, IRB.getPtrTy()), Size,
740 (Value *)TD, (Value *)Flags});
741
742 // We appear to have the right type. Make sure that all other bytes in
743 // the type are still marked as interior bytes. If not, call the runtime.
744 IRB.SetInsertPoint(GoodTDTerm);
745 Value *NotAllBadTD = IRB.getFalse();
746 for (uint64_t i = 1; i < AccessSize; ++i) {
747 Value *BadShadowData = IRB.CreateIntToPtr(
748 IRB.CreateAdd(ShadowDataInt, ConstantInt::get(IntptrTy, i << PtrShift)),
749 Int8PtrPtrTy);
750 Value *ILdTD = IRB.CreatePtrToInt(
751 IRB.CreateLoad(IRB.getPtrTy(), BadShadowData), IntptrTy);
752 NotAllBadTD = IRB.CreateOr(
753 NotAllBadTD, IRB.CreateICmpSGE(ILdTD, ConstantInt::get(IntptrTy, 0)));
754 }
755
757 NotAllBadTD, &*IRB.GetInsertPoint(), false, UnlikelyBW);
758 IRB.SetInsertPoint(BadITDTerm);
759 IRB.CreateCall(TysanCheck, {IRB.CreateBitCast(Ptr, IRB.getPtrTy()), Size,
760 (Value *)TD, (Value *)Flags});
761 return true;
762}
763
764bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,
765 Instruction *AppMemMask,
766 const DataLayout &DL) {
768 BasicBlock *BB;
769 Function *F;
770
771 if (auto *I = dyn_cast<Instruction>(V)) {
773 BB = I->getParent();
774 F = BB->getParent();
775 } else {
776 auto *A = cast<Argument>(V);
777 F = A->getParent();
778 BB = &F->getEntryBlock();
779 IP = BB->getFirstInsertionPt();
780
781 // Find the next insert point after both ShadowBase and AppMemMask.
782 if (IP->comesBefore(ShadowBase))
783 IP = ShadowBase->getNextNode()->getIterator();
784 if (IP->comesBefore(AppMemMask))
785 IP = AppMemMask->getNextNode()->getIterator();
786 }
787
788 Value *Dest, *Size, *Src = nullptr;
789 bool NeedsMemMove = false;
790 IRBuilder<> IRB(BB, IP);
791
792 auto GetAllocaSize = [&](AllocaInst *AI) {
793 return IRB.CreateMul(
794 IRB.CreateZExtOrTrunc(AI->getArraySize(), IntptrTy),
795 ConstantInt::get(IntptrTy,
796 DL.getTypeAllocSize(AI->getAllocatedType())));
797 };
798
799 if (auto *A = dyn_cast<Argument>(V)) {
800 assert(A->hasByValAttr() && "Type reset for non-byval argument?");
801
802 Dest = A;
803 Size =
804 ConstantInt::get(IntptrTy, DL.getTypeAllocSize(A->getParamByValType()));
805 } else {
806 auto *I = cast<Instruction>(V);
807 if (auto *MI = dyn_cast<MemIntrinsic>(I)) {
808 if (MI->getDestAddressSpace() != 0)
809 return false;
810
811 Dest = MI->getDest();
812 Size = MI->getLength();
813
814 if (auto *MTI = dyn_cast<MemTransferInst>(MI)) {
815 if (MTI->getSourceAddressSpace() == 0) {
816 Src = MTI->getSource();
817 NeedsMemMove = isa<MemMoveInst>(MTI);
818 }
819 }
820 } else if (auto *II = dyn_cast<LifetimeIntrinsic>(I)) {
821 auto *AI = dyn_cast<AllocaInst>(II->getArgOperand(0));
822 if (!AI)
823 return false;
824
825 Size = GetAllocaSize(AI);
826 Dest = II->getArgOperand(0);
827 } else if (auto *AI = dyn_cast<AllocaInst>(I)) {
828 // We need to clear the types for new stack allocations (or else we might
829 // read stale type information from a previous function execution).
830
831 IRB.SetInsertPoint(&*std::next(BasicBlock::iterator(I)));
833
834 Size = GetAllocaSize(AI);
835 Dest = I;
836 } else {
837 return false;
838 }
839 }
840
841 if (!ShadowBase)
842 ShadowBase = getShadowBase(*F);
843 if (!AppMemMask)
844 AppMemMask = getAppMemMask(*F);
845
846 Value *ShadowDataInt = IRB.CreateAdd(
847 IRB.CreateShl(
848 IRB.CreateAnd(IRB.CreatePtrToInt(Dest, IntptrTy), AppMemMask),
849 PtrShift),
850 ShadowBase);
851 Value *ShadowData = IRB.CreateIntToPtr(ShadowDataInt, IRB.getPtrTy());
852
853 if (!Src) {
854 IRB.CreateMemSet(ShadowData, IRB.getInt8(0), IRB.CreateShl(Size, PtrShift),
855 Align(1ull << PtrShift));
856 return true;
857 }
858
859 Value *SrcShadowDataInt = IRB.CreateAdd(
860 IRB.CreateShl(
861 IRB.CreateAnd(IRB.CreatePtrToInt(Src, IntptrTy), AppMemMask),
862 PtrShift),
863 ShadowBase);
864 Value *SrcShadowData = IRB.CreateIntToPtr(SrcShadowDataInt, IRB.getPtrTy());
865
866 if (NeedsMemMove) {
867 IRB.CreateMemMove(ShadowData, Align(1ull << PtrShift), SrcShadowData,
868 Align(1ull << PtrShift), IRB.CreateShl(Size, PtrShift));
869 } else {
870 IRB.CreateMemCpy(ShadowData, Align(1ull << PtrShift), SrcShadowData,
871 Align(1ull << PtrShift), IRB.CreateShl(Size, PtrShift));
872 }
873
874 return true;
875}
876
879 Function *TysanCtorFunction;
880 std::tie(TysanCtorFunction, std::ignore) =
882 kTysanInitName, /*InitArgTypes=*/{},
883 /*InitArgs=*/{});
884
885 TypeSanitizer TySan(M);
886 TySan.instrumentGlobals(M);
887 appendToGlobalCtors(M, TysanCtorFunction, 0);
888
889 auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
890 for (Function &F : M) {
892 TySan.sanitizeFunction(F, TLI);
893 }
894
896}
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")
DXIL Resource Access
std::string Name
uint64_t Size
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file provides utility analysis objects describing memory locations.
This file contains the declarations for metadata subclasses.
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)
Definition: Statistic.h:167
This file contains some functions that are useful when dealing with strings.
static const char *const kTysanInitName
static Value * convertToShadowDataInt(IRBuilder<> &IRB, Value *Ptr, Type *IntptrTy, uint64_t PtrShift, Value *ShadowBase, Value *AppMemMask)
static const char *const kTysanShadowMemoryAddress
static const char LUT[]
static const char *const kTysanGVNamePrefix
static const char *const kTysanModuleCtorName
static const char *const kTysanAppMemMask
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.
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
static std::string encodeName(StringRef Name)
an instruction to allocate memory on the stack
Definition: Instructions.h:64
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:412
AttributeList addFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a function attribute to the list.
Definition: Attributes.h:593
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
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...
Definition: BasicBlock.cpp:393
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:206
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:213
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:170
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.
Definition: Constants.cpp:2989
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.h:131
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1380
This is an important base class in LLVM.
Definition: Constant.h:43
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:373
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:170
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:166
LLVM_ABI void setComdat(Comdat *C)
Definition: Globals.cpp:214
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:60
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:56
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:2100
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.
Definition: IRBuilder.h:687
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2357
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:202
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2199
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:512
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2333
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition: IRBuilder.h:729
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2204
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition: IRBuilder.h:1847
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1492
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.
Definition: IRBuilder.h:630
LLVMContext & getContext() const
Definition: IRBuilder.h:203
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1551
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1860
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1403
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2194
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:507
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition: IRBuilder.h:2651
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2508
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition: IRBuilder.h:605
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
Definition: IRBuilder.h:2646
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition: IRBuilder.h:207
LLVM_ABI void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.cpp:64
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
Definition: IRBuilder.h:1573
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1437
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2780
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:585
Class to represent integer types.
Definition: DerivedTypes.h:42
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Definition: MD5.h:42
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:189
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:234
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
Definition: MDBuilder.cpp:38
Metadata node.
Definition: Metadata.h:1077
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1445
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1451
LLVMContext & getContext() const
Definition: Metadata.h:1241
A single uniqued string.
Definition: Metadata.h:720
LLVM_ABI StringRef getString() const
Definition: Metadata.cpp:617
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.
Definition: Module.h:67
A tuple of MDNodes.
Definition: Metadata.h:1753
iterator_range< op_iterator > operands()
Definition: Metadata.h:1849
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:115
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:168
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:356
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:254
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
Class to represent struct types.
Definition: DerivedTypes.h:218
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.
Definition: Type.cpp:414
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.
Definition: Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static LLVM_ABI Type * getVoidTy(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.
Definition: Type.h:311
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
LLVM_ABI bool isSwiftError() const
Return true if this value is a swifterror value.
Definition: Value.cpp:1119
const ParentTy * getParent() const
Definition: ilist_node.h:34
self_iterator getIterator()
Definition: ilist_node.h:134
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:359
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
@ Length
Definition: DWP.cpp:477
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:157
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...
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.
Definition: ModuleUtils.cpp:74
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...
Definition: Local.cpp:3829
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:777
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
LLVM_ABI SmallString< 32 > digest() const
Definition: MD5.cpp:281
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)