173 #include "llvm/IR/IntrinsicsX86.h" 202 using namespace llvm;
204 #define DEBUG_TYPE "msan" 222 cl::desc(
"Track origins (allocation sites) of poisoned memory"),
226 cl::desc(
"keep going after reporting a UMR"),
230 cl::desc(
"poison uninitialized stack variables"),
234 cl::desc(
"poison uninitialized stack variables with a call"),
238 cl::desc(
"poison uninitialized stack variables with the given pattern"),
246 cl::desc(
"propagate shadow through ICmpEQ and ICmpNE"),
250 cl::desc(
"exact handling of relational integer ICmp"),
254 "msan-handle-lifetime-intrinsics",
256 "when possible, poison scoped variables at the beginning of the scope " 257 "(slower, but more precise)"),
271 "msan-handle-asm-conservative",
282 cl::desc(
"report accesses through a pointer which has poisoned shadow"),
286 cl::desc(
"print out instructions with default strict semantics"),
290 "msan-instrumentation-with-call-threshold",
292 "If the function being instrumented requires more than " 293 "this number of checks and origin stores, use callbacks instead of " 294 "inline checks (-1 means never use callbacks)."),
299 cl::desc(
"Enable KernelMemorySanitizer instrumentation"),
306 cl::desc(
"Insert checks for constant shadow values"),
312 cl::desc(
"Place MSan constructors in comdat sections"),
318 cl::desc(
"Define custom MSan AndMask"),
322 cl::desc(
"Define custom MSan XorMask"),
326 cl::desc(
"Define custom MSan ShadowBase"),
330 cl::desc(
"Define custom MSan OriginBase"),
342 struct MemoryMapParams {
349 struct PlatformMemoryMapParams {
350 const MemoryMapParams *bits32;
351 const MemoryMapParams *bits64;
366 #ifdef MSAN_LINUX_X86_64_OLD_MAPPING 465 class MemorySanitizer {
474 MemorySanitizer(MemorySanitizer &&) =
delete;
475 MemorySanitizer &operator=(MemorySanitizer &&) =
delete;
476 MemorySanitizer(
const MemorySanitizer &) =
delete;
477 MemorySanitizer &operator=(
const MemorySanitizer &) =
delete;
482 friend struct MemorySanitizerVisitor;
483 friend struct VarArgAMD64Helper;
484 friend struct VarArgMIPS64Helper;
485 friend struct VarArgAArch64Helper;
486 friend struct VarArgPowerPC64Helper;
488 void initializeModule(
Module &M);
489 void initializeCallbacks(
Module &M);
490 void createKernelApi(
Module &M);
491 void createUserspaceApi(
Module &M);
513 Value *ParamOriginTLS;
519 Value *RetvalOriginTLS;
527 Value *VAArgOriginTLS;
531 Value *VAArgOverflowSizeTLS;
538 bool CallbacksInitialized =
false;
579 const MemoryMapParams *MapParams;
583 MemoryMapParams CustomMapParams;
588 MDNode *OriginStoreWeights;
594 void insertModuleCtor(
Module &M) {
596 M, kMsanModuleCtorName, kMsanInitName,
615 struct MemorySanitizerLegacyPass :
public FunctionPass {
621 StringRef getPassName()
const override {
return "MemorySanitizerLegacyPass"; }
628 return MSan->sanitizeFunction(
629 F, getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F));
631 bool doInitialization(
Module &M)
override;
650 MemorySanitizer Msan(*F.
getParent(), Options);
667 "MemorySanitizer: detects uninitialized reads.",
false,
671 "MemorySanitizer: detects uninitialized reads.",
false,
676 return new MemorySanitizerLegacyPass(Options);
692 void MemorySanitizer::createKernelApi(
Module &M) {
697 RetvalOriginTLS =
nullptr;
699 ParamOriginTLS =
nullptr;
701 VAArgOriginTLS =
nullptr;
702 VAArgOverflowSizeTLS =
nullptr;
724 for (
int ind = 0,
size = 1; ind < 4; ind++,
size <<= 1) {
725 std::string name_load =
727 std::string name_store =
736 "__msan_metadata_ptr_for_load_n", RetTy,
739 "__msan_metadata_ptr_for_store_n", RetTy,
753 nullptr, Name,
nullptr,
759 void MemorySanitizer::createUserspaceApi(
Module &M) {
765 :
"__msan_warning_noreturn";
791 VAArgOverflowSizeTLS =
797 unsigned AccessSize = 1 << AccessSizeIndex;
798 std::string FunctionName =
"__msan_maybe_warning_" +
itostr(AccessSize);
803 FunctionName =
"__msan_maybe_store_origin_" +
itostr(AccessSize);
818 void MemorySanitizer::initializeCallbacks(
Module &M) {
820 if (CallbacksInitialized)
842 MsanInstrumentAsmStoreFn =
849 createUserspaceApi(M);
851 CallbacksInitialized =
true;
857 isStore ? MsanMetadataPtrForStore_1_8 : MsanMetadataPtrForLoad_1_8;
875 void MemorySanitizer::initializeModule(
Module &M) {
878 bool ShadowPassed =
ClShadowBase.getNumOccurrences() > 0;
879 bool OriginPassed =
ClOriginBase.getNumOccurrences() > 0;
881 if (ShadowPassed || OriginPassed) {
886 MapParams = &CustomMapParams;
889 switch (TargetTriple.getOS()) {
891 switch (TargetTriple.getArch()) {
903 switch (TargetTriple.getArch()) {
912 switch (TargetTriple.getArch()) {
948 if (!CompileKernel) {
965 bool MemorySanitizerLegacyPass::doInitialization(
Module &M) {
968 MSan.emplace(M, Options);
982 struct VarArgHelper {
983 virtual ~VarArgHelper() =
default;
992 virtual void visitVACopyInst(
VACopyInst &I) = 0;
998 virtual void finalizeInstrumentation() = 0;
1001 struct MemorySanitizerVisitor;
1006 MemorySanitizerVisitor &Visitor);
1009 if (TypeSize <= 8)
return 0;
1021 struct MemorySanitizerVisitor :
public InstVisitor<MemorySanitizerVisitor> {
1023 MemorySanitizer &MS;
1026 std::unique_ptr<VarArgHelper> VAHelper;
1033 bool PropagateShadow;
1036 bool CheckReturnValue;
1038 struct ShadowOriginAndInsertPoint {
1044 : Shadow(S), Origin(O), OrigIns(I) {}
1052 MemorySanitizerVisitor(
Function &F, MemorySanitizer &MS,
1055 bool SanitizeFunction = F.
hasFnAttribute(Attribute::SanitizeMemory);
1056 InsertChecks = SanitizeFunction;
1057 PropagateShadow = SanitizeFunction;
1062 CheckReturnValue = SanitizeFunction && (F.
getName() ==
"main");
1065 if (MS.CompileKernel)
1066 ActualFnStart = insertKmsanPrologue(F);
1071 <<
"MemorySanitizer is not inserting checks into '" 1076 if (MS.TrackOrigins <= 1)
return V;
1077 return IRB.
CreateCall(MS.MsanChainOriginFn, V);
1083 if (IntptrSize == kOriginSize)
return Origin;
1084 assert(IntptrSize == kOriginSize * 2);
1095 assert(IntptrAlignment >= kMinOriginAlignment);
1096 assert(IntptrSize >= kOriginSize);
1099 Align CurrentAlignment = Alignment;
1100 if (Alignment >= IntptrAlignment && IntptrSize > kOriginSize) {
1101 Value *IntptrOrigin = originToIntptr(IRB, Origin);
1102 Value *IntptrOriginPtr =
1104 for (
unsigned i = 0; i < Size / IntptrSize; ++i) {
1109 CurrentAlignment = IntptrAlignment;
1113 for (
unsigned i = Ofs; i < (Size + kOriginSize - 1) / kOriginSize; ++i) {
1122 Value *OriginPtr,
Align Alignment,
bool AsCall) {
1124 const Align OriginAlignment =
std::max(kMinOriginAlignment, Alignment);
1127 paintOrigin(IRB, updateOrigin(Origin, IRB), OriginPtr, StoreSize,
1130 Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB);
1131 if (
auto *ConstantShadow = dyn_cast<Constant>(ConvertedShadow)) {
1133 paintOrigin(IRB, updateOrigin(Origin, IRB), OriginPtr, StoreSize,
1138 unsigned TypeSizeInBits =
1144 ConvertedShadow, IRB.
getIntNTy(8 * (1 << SizeIndex)));
1150 ConvertedShadow, getCleanShadow(ConvertedShadow),
"_mscmp");
1154 paintOrigin(IRBNew, updateOrigin(Origin, IRBNew), OriginPtr, StoreSize,
1160 void materializeStores(
bool InstrumentWithCalls) {
1163 Value *Val =
SI->getValueOperand();
1164 Value *Addr =
SI->getPointerOperand();
1165 Value *Shadow =
SI->isAtomic() ? getCleanShadow(Val) : getShadow(Val);
1166 Value *ShadowPtr, *OriginPtr;
1169 const Align OriginAlignment =
std::max(kMinOriginAlignment, Alignment);
1170 std::tie(ShadowPtr, OriginPtr) =
1171 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment,
true);
1179 SI->setOrdering(addReleaseOrdering(
SI->getOrdering()));
1181 if (MS.TrackOrigins && !
SI->isAtomic())
1182 storeOrigin(IRB, Addr, Shadow, getOrigin(Val), OriginPtr,
1183 OriginAlignment, InstrumentWithCalls);
1191 if (MS.CompileKernel) {
1194 if (MS.TrackOrigins) {
1209 Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB);
1212 if (
auto *ConstantShadow = dyn_cast<Constant>(ConvertedShadow)) {
1214 insertWarningFn(IRB, Origin);
1225 Value *ConvertedShadow2 =
1227 IRB.
CreateCall(Fn, {ConvertedShadow2, MS.TrackOrigins && Origin
1232 getCleanShadow(ConvertedShadow),
"_mscmp");
1235 !MS.Recover, MS.ColdCallWeights);
1238 insertWarningFn(IRB, Origin);
1243 void materializeChecks(
bool InstrumentWithCalls) {
1244 for (
const auto &ShadowData : InstrumentationList) {
1246 Value *Shadow = ShadowData.Shadow;
1247 Value *Origin = ShadowData.Origin;
1248 materializeOneCheck(OrigIns, Shadow, Origin, InstrumentWithCalls);
1259 MS.ParamTLS = IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1260 {Zero, IRB.getInt32(0)},
"param_shadow");
1261 MS.RetvalTLS = IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1262 {Zero, IRB.getInt32(1)},
"retval_shadow");
1263 MS.VAArgTLS = IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1264 {Zero, IRB.getInt32(2)},
"va_arg_shadow");
1265 MS.VAArgOriginTLS = IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1266 {Zero, IRB.getInt32(3)},
"va_arg_origin");
1267 MS.VAArgOverflowSizeTLS =
1268 IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1269 {Zero, IRB.getInt32(4)},
"va_arg_overflow_size");
1270 MS.ParamOriginTLS = IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1271 {Zero, IRB.getInt32(5)},
"param_origin");
1272 MS.RetvalOriginTLS =
1273 IRB.
CreateGEP(MS.MsanContextStateTy, ContextState,
1274 {Zero, IRB.getInt32(6)},
"retval_origin");
1293 for (
PHINode *PN : ShadowPHINodes) {
1294 PHINode *PNS = cast<PHINode>(getShadow(PN));
1295 PHINode *PNO = MS.TrackOrigins ? cast<PHINode>(getOrigin(PN)) :
nullptr;
1296 size_t NumValues = PN->getNumIncomingValues();
1297 for (
size_t v = 0; v < NumValues; v++) {
1298 PNS->
addIncoming(getShadow(PN, v), PN->getIncomingBlock(v));
1299 if (PNO) PNO->addIncoming(getOrigin(PN, v), PN->getIncomingBlock(v));
1303 VAHelper->finalizeInstrumentation();
1307 if (InstrumentLifetimeStart) {
1308 for (
auto Item : LifetimeStartList) {
1309 instrumentAlloca(*Item.second, Item.first);
1310 AllocaSet.
erase(Item.second);
1316 instrumentAlloca(*AI);
1319 InstrumentationList.
size() + StoreList.
size() >
1323 materializeChecks(InstrumentWithCalls);
1327 materializeStores(InstrumentWithCalls);
1334 return getShadowTy(V->
getType());
1347 if (
VectorType *VT = dyn_cast<VectorType>(OrigTy)) {
1350 VT->getNumElements());
1352 if (
ArrayType *AT = dyn_cast<ArrayType>(OrigTy)) {
1354 AT->getNumElements());
1358 for (
unsigned i = 0, n =
ST->getNumElements(); i < n; i++)
1359 Elements.
push_back(getShadowTy(
ST->getElementType(i)));
1370 if (
VectorType *vt = dyn_cast<VectorType>(ty))
1378 Type *NoVecTy = getShadowTyNoVec(Ty);
1379 if (Ty == NoVecTy)
return V;
1390 uint64_t AndMask = MS.MapParams->AndMask;
1395 uint64_t XorMask = MS.MapParams->XorMask;
1407 std::pair<Value *, Value *>
1410 Value *ShadowOffset = getShadowPtrOffset(Addr, IRB);
1411 Value *ShadowLong = ShadowOffset;
1412 uint64_t ShadowBase = MS.MapParams->ShadowBase;
1413 if (ShadowBase != 0) {
1420 Value *OriginPtr =
nullptr;
1421 if (MS.TrackOrigins) {
1422 Value *OriginLong = ShadowOffset;
1423 uint64_t OriginBase = MS.MapParams->OriginBase;
1424 if (OriginBase != 0)
1427 if (!Alignment || *Alignment < kMinOriginAlignment) {
1428 uint64_t
Mask = kMinOriginAlignment.
value() - 1;
1435 return std::make_pair(ShadowPtr, OriginPtr);
1438 std::pair<Value *, Value *> getShadowOriginPtrKernel(
Value *Addr,
1442 Value *ShadowOriginPtrs;
1446 FunctionCallee Getter = MS.getKmsanShadowOriginAccessFn(isStore, Size);
1450 ShadowOriginPtrs = IRB.
CreateCall(Getter, AddrCast);
1453 ShadowOriginPtrs = IRB.
CreateCall(isStore ? MS.MsanMetadataPtrForStoreN
1454 : MS.MsanMetadataPtrForLoadN,
1455 {AddrCast, SizeVal});
1461 return std::make_pair(ShadowPtr, OriginPtr);
1464 std::pair<Value *, Value *> getShadowOriginPtr(
Value *Addr,
IRBuilder<> &IRB,
1468 if (MS.CompileKernel)
1469 return getShadowOriginPtrKernel(Addr, IRB, ShadowTy, isStore);
1470 return getShadowOriginPtrUserspace(Addr, IRB, ShadowTy, Alignment);
1488 if (!MS.TrackOrigins)
1507 return MS.RetvalOriginTLS;
1512 assert(!ShadowMap.
count(V) &&
"Values may only have one shadow");
1513 ShadowMap[V] = PropagateShadow ? SV : getCleanShadow(V);
1518 if (!MS.TrackOrigins)
return;
1519 assert(!OriginMap.
count(V) &&
"Values may only have one origin");
1520 LLVM_DEBUG(
dbgs() <<
"ORIGIN: " << *V <<
" ==> " << *Origin <<
"\n");
1521 OriginMap[V] = Origin;
1525 Type *ShadowTy = getShadowTy(OrigTy);
1536 return getCleanShadow(V->
getType());
1542 if (isa<IntegerType>(ShadowTy) || isa<VectorType>(ShadowTy))
1544 if (
ArrayType *AT = dyn_cast<ArrayType>(ShadowTy)) {
1546 getPoisonedShadow(AT->getElementType()));
1551 for (
unsigned i = 0, n =
ST->getNumElements(); i < n; i++)
1552 Vals.
push_back(getPoisonedShadow(
ST->getElementType(i)));
1560 Type *ShadowTy = getShadowTy(V);
1563 return getPoisonedShadow(ShadowTy);
1567 Value *getCleanOrigin() {
1576 if (!PropagateShadow)
return getCleanShadow(V);
1578 if (
I->getMetadata(
"nosanitize"))
1579 return getCleanShadow(V);
1581 Value *Shadow = ShadowMap[V];
1583 LLVM_DEBUG(
dbgs() <<
"No shadow: " << *V <<
"\n" << *(
I->getParent()));
1585 assert(Shadow &&
"No shadow for a value");
1589 if (
UndefValue *U = dyn_cast<UndefValue>(V)) {
1590 Value *AllOnes = PoisonUndef ? getPoisonedShadow(V) : getCleanShadow(V);
1591 LLVM_DEBUG(
dbgs() <<
"Undef: " << *U <<
" ==> " << *AllOnes <<
"\n");
1595 if (
Argument *A = dyn_cast<Argument>(V)) {
1597 Value **ShadowPtr = &ShadowMap[V];
1602 unsigned ArgOffset = 0;
1604 for (
auto &FArg : F->
args()) {
1605 if (!FArg.getType()->isSized()) {
1615 Value *
Base = getShadowPtrForArgument(&FArg, EntryIRB, ArgOffset);
1616 if (FArg.hasByValAttr()) {
1623 Value *CpShadowPtr =
1624 getShadowOriginPtr(V, EntryIRB, EntryIRB.getInt8Ty(), ArgAlign,
1630 EntryIRB.CreateMemSet(
1634 const Align CopyAlign = std::min(ArgAlign, kShadowTLSAlignment);
1635 Value *Cpy = EntryIRB.CreateMemCpy(CpShadowPtr, CopyAlign, Base,
1640 *ShadowPtr = getCleanShadow(V);
1644 *ShadowPtr = getCleanShadow(V);
1646 *ShadowPtr = EntryIRB.CreateAlignedLoad(
1647 getShadowTy(&FArg), Base, kShadowTLSAlignment.
value());
1651 <<
" ARG: " << FArg <<
" ==> " << **ShadowPtr <<
"\n");
1652 if (MS.TrackOrigins && !Overflow) {
1654 getOriginPtrForArgument(&FArg, EntryIRB, ArgOffset);
1655 setOrigin(A, EntryIRB.CreateLoad(MS.OriginTy, OriginPtr));
1657 setOrigin(A, getCleanOrigin());
1660 ArgOffset +=
alignTo(Size, kShadowTLSAlignment);
1662 assert(*ShadowPtr &&
"Could not find shadow for an argument");
1666 return getCleanShadow(V);
1676 if (!MS.TrackOrigins)
return nullptr;
1677 if (!PropagateShadow)
return getCleanOrigin();
1678 if (isa<Constant>(V))
return getCleanOrigin();
1679 assert((isa<Instruction>(V) || isa<Argument>(V)) &&
1680 "Unexpected value type in getOrigin()");
1683 return getCleanOrigin();
1685 Value *Origin = OriginMap[V];
1686 assert(Origin &&
"Missing origin");
1701 if (!InsertChecks)
return;
1704 assert((isa<IntegerType>(ShadowTy) || isa<VectorType>(ShadowTy)) &&
1705 "Can only insert checks for integer and vector shadow types");
1708 ShadowOriginAndInsertPoint(Shadow, Origin, OrigIns));
1717 Value *Shadow, *Origin;
1719 Shadow = getShadow(Val);
1720 if (!Shadow)
return;
1721 Origin = getOrigin(Val);
1723 Shadow = dyn_cast_or_null<Instruction>(getShadow(Val));
1724 if (!Shadow)
return;
1725 Origin = dyn_cast_or_null<Instruction>(getOrigin(Val));
1727 insertShadowCheck(Shadow, Origin, OrigIns);
1779 Type *ShadowTy = getShadowTy(&I);
1781 Value *ShadowPtr =
nullptr, *OriginPtr =
nullptr;
1783 if (PropagateShadow) {
1784 std::tie(ShadowPtr, OriginPtr) =
1785 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment,
false);
1787 Alignment.
value(),
"_msld"));
1789 setShadow(&I, getCleanShadow(&I));
1798 if (MS.TrackOrigins) {
1799 if (PropagateShadow) {
1800 const Align OriginAlignment =
std::max(kMinOriginAlignment, Alignment);
1802 OriginAlignment.
value()));
1804 setOrigin(&I, getCleanOrigin());
1820 assert(isa<AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I));
1829 insertShadowCheck(Addr, &I);
1834 if (isa<AtomicCmpXchgInst>(I))
1839 setShadow(&I, getCleanShadow(&I));
1840 setOrigin(&I, getCleanOrigin());
1857 setShadow(&I, IRB.CreateExtractElement(getShadow(&I, 0), I.
getOperand(1),
1859 setOrigin(&I, getOrigin(&I, 0));
1865 setShadow(&I, IRB.CreateInsertElement(getShadow(&I, 0), getShadow(&I, 1),
1867 setOriginForNaryOp(I);
1873 setShadow(&I, IRB.CreateShuffleVector(getShadow(&I, 0), getShadow(&I, 1),
1875 setOriginForNaryOp(I);
1882 setOrigin(&I, getOrigin(&I, 0));
1888 setOrigin(&I, getOrigin(&I, 0));
1894 setOrigin(&I, getOrigin(&I, 0));
1901 if (
auto *CI = dyn_cast<CallInst>(I.
getOperand(0)))
1902 if (CI->isMustTailCall())
1905 setShadow(&I, IRB.
CreateBitCast(getShadow(&I, 0), getShadowTy(&I)));
1906 setOrigin(&I, getOrigin(&I, 0));
1911 setShadow(&I, IRB.
CreateIntCast(getShadow(&I, 0), getShadowTy(&I),
false,
1912 "_msprop_ptrtoint"));
1913 setOrigin(&I, getOrigin(&I, 0));
1918 setShadow(&I, IRB.
CreateIntCast(getShadow(&I, 0), getShadowTy(&I),
false,
1919 "_msprop_inttoptr"));
1920 setOrigin(&I, getOrigin(&I, 0));
1923 void visitFPToSIInst(
CastInst& I) { handleShadowOr(I); }
1924 void visitFPToUIInst(
CastInst& I) { handleShadowOr(I); }
1925 void visitSIToFPInst(
CastInst& I) { handleShadowOr(I); }
1926 void visitUIToFPInst(
CastInst& I) { handleShadowOr(I); }
1927 void visitFPExtInst(
CastInst& I) { handleShadowOr(I); }
1928 void visitFPTruncInst(
CastInst& I) { handleShadowOr(I); }
1942 Value *S1 = getShadow(&I, 0);
1943 Value *S2 = getShadow(&I, 1);
1953 setShadow(&I, IRB.
CreateOr({S1S2, V1S2, S1V2}));
1954 setOriginForNaryOp(I);
1964 Value *S1 = getShadow(&I, 0);
1965 Value *S2 = getShadow(&I, 1);
1975 setShadow(&I, IRB.
CreateOr({S1S2, V1S2, S1V2}));
1976 setOriginForNaryOp(I);
1994 template <
bool CombineShadow>
1996 Value *Shadow =
nullptr;
1997 Value *Origin =
nullptr;
1999 MemorySanitizerVisitor *MSV;
2003 : IRB(IRB), MSV(MSV) {}
2007 if (CombineShadow) {
2012 OpShadow = MSV->CreateShadowCast(IRB, OpShadow, Shadow->
getType());
2013 Shadow = IRB.
CreateOr(Shadow, OpShadow,
"_msprop");
2017 if (MSV->MS.TrackOrigins) {
2024 if (!ConstOrigin || !ConstOrigin->
isNullValue()) {
2025 Value *FlatShadow = MSV->convertToShadowTyNoVec(OpShadow, IRB);
2027 IRB.
CreateICmpNE(FlatShadow, MSV->getCleanShadow(FlatShadow));
2037 Value *OpShadow = MSV->getShadow(V);
2038 Value *OpOrigin = MSV->MS.TrackOrigins ? MSV->getOrigin(V) :
nullptr;
2039 return Add(OpShadow, OpOrigin);
2045 if (CombineShadow) {
2047 Shadow = MSV->CreateShadowCast(IRB, Shadow, MSV->getShadowTy(I));
2048 MSV->setShadow(I, Shadow);
2050 if (MSV->MS.TrackOrigins) {
2052 MSV->setOrigin(I, Origin);
2062 if (!MS.TrackOrigins)
return;
2064 OriginCombiner
OC(
this, IRB);
2070 size_t VectorOrPrimitiveTypeSizeInBits(
Type *Ty) {
2072 "Vector of pointers is not a valid shadow type");
2083 size_t srcSizeInBits = VectorOrPrimitiveTypeSizeInBits(srcTy);
2084 size_t dstSizeInBits = VectorOrPrimitiveTypeSizeInBits(dstTy);
2085 if (srcSizeInBits > 1 && dstSizeInBits == 1)
2102 Type *ShadowTy = getShadowTy(V);
2114 ShadowAndOriginCombiner
SC(
this, IRB);
2139 for (
unsigned Idx = 0; Idx < NumElements; ++Idx) {
2142 const APInt &V = Elt->getValue();
2151 if (
ConstantInt *Elt = dyn_cast<ConstantInt>(ConstArg)) {
2152 const APInt &V = Elt->getValue();
2162 IRB.
CreateMul(getShadow(OtherArg), ShadowMul,
"msprop_mul_cst"));
2163 setOrigin(&I, getOrigin(OtherArg));
2169 if (constOp0 && !constOp1)
2170 handleMulByConstant(I, constOp0, I.
getOperand(1));
2171 else if (constOp1 && !constOp0)
2172 handleMulByConstant(I, constOp1, I.
getOperand(0));
2188 setShadow(&I, getShadow(&I, 0));
2189 setOrigin(&I, getOrigin(&I, 0));
2206 void handleEqualityComparison(
ICmpInst &I) {
2210 Value *Sa = getShadow(A);
2211 Value *Sb = getShadow(B);
2237 setOriginForNaryOp(I);
2279 void handleRelationalComparisonExact(
ICmpInst &I) {
2283 Value *Sa = getShadow(A);
2284 Value *Sb = getShadow(B);
2297 getLowestPossibleValue(IRB, A, Sa, IsSigned),
2298 getHighestPossibleValue(IRB, B, Sb, IsSigned));
2300 getHighestPossibleValue(IRB, A, Sa, IsSigned),
2301 getLowestPossibleValue(IRB, B, Sb, IsSigned));
2304 setOriginForNaryOp(I);
2311 void handleSignedRelationalComparison(
ICmpInst &I) {
2315 if ((constOp = dyn_cast<Constant>(I.
getOperand(1)))) {
2318 }
else if ((constOp = dyn_cast<Constant>(I.
getOperand(0)))) {
2333 setShadow(&I, Shadow);
2334 setOrigin(&I, getOrigin(op));
2346 handleEqualityComparison(I);
2352 handleRelationalComparisonExact(I);
2356 handleSignedRelationalComparison(I);
2362 handleRelationalComparisonExact(I);
2377 Value *S1 = getShadow(&I, 0);
2378 Value *S2 = getShadow(&I, 1);
2383 setShadow(&I, IRB.
CreateOr(Shift, S2Conv));
2384 setOriginForNaryOp(I);
2405 {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()),
2406 IRB.CreatePointerCast(I.getArgOperand(1), IRB.getInt8PtrTy()),
2407 IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)});
2419 {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()),
2420 IRB.CreatePointerCast(I.getArgOperand(1), IRB.getInt8PtrTy()),
2421 IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)});
2430 {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()),
2431 IRB.CreateIntCast(I.getArgOperand(1), IRB.getInt32Ty(), false),
2432 IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)});
2437 VAHelper->visitVAStartInst(I);
2441 VAHelper->visitVACopyInst(I);
2451 Value *Shadow = getShadow(&I, 1);
2452 Value *ShadowPtr, *OriginPtr;
2456 std::tie(ShadowPtr, OriginPtr) = getShadowOriginPtr(
2461 insertShadowCheck(Addr, &I);
2464 if (MS.TrackOrigins) IRB.
CreateStore(getOrigin(&I, 1), OriginPtr);
2476 Type *ShadowTy = getShadowTy(&I);
2477 Value *ShadowPtr =
nullptr, *OriginPtr =
nullptr;
2478 if (PropagateShadow) {
2482 std::tie(ShadowPtr, OriginPtr) =
2483 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment,
false);
2485 Alignment.
value(),
"_msld"));
2487 setShadow(&I, getCleanShadow(&I));
2491 insertShadowCheck(Addr, &I);
2493 if (MS.TrackOrigins) {
2494 if (PropagateShadow)
2495 setOrigin(&I, IRB.
CreateLoad(MS.OriginTy, OriginPtr));
2497 setOrigin(&I, getCleanOrigin());
2517 for (
unsigned i = 0; i < NumArgOperands; ++i) {
2524 ShadowAndOriginCombiner
SC(
this, IRB);
2525 for (
unsigned i = 0; i < NumArgOperands; ++i)
2544 if (NumArgOperands == 0)
2547 if (NumArgOperands == 2 &&
2553 return handleVectorStoreIntrinsic(I);
2556 if (NumArgOperands == 1 &&
2561 return handleVectorLoadIntrinsic(I);
2565 if (maybeHandleSimpleNomemIntrinsic(I))
2573 setShadow(&I, getShadow(&I, 0));
2574 setOrigin(&I, getOrigin(&I, 0));
2584 InstrumentLifetimeStart =
false;
2585 LifetimeStartList.
push_back(std::make_pair(&I, AI));
2594 setShadow(&I, IRB.
CreateCall(BswapFunc, getShadow(Op)));
2595 setOrigin(&I, getOrigin(Op));
2613 void handleVectorConvertIntrinsic(
IntrinsicInst &I,
int NumUsedElements) {
2615 Value *CopyOp, *ConvertOp;
2640 Value *ConvertShadow = getShadow(ConvertOp);
2641 Value *AggShadow =
nullptr;
2645 for (
int i = 1; i < NumUsedElements; ++i) {
2648 AggShadow = IRB.
CreateOr(AggShadow, MoreShadow);
2651 AggShadow = ConvertShadow;
2654 insertShadowCheck(AggShadow, getOrigin(ConvertOp), &I);
2661 Value *ResultShadow = getShadow(CopyOp);
2663 for (
int i = 0; i < NumUsedElements; ++i) {
2668 setShadow(&I, ResultShadow);
2669 setOrigin(&I, getOrigin(CopyOp));
2671 setShadow(&I, getCleanShadow(&I));
2672 setOrigin(&I, getCleanOrigin());
2680 S = CreateShadowCast(IRB, S, IRB.
getInt64Ty(),
true);
2683 return CreateShadowCast(IRB, S2, T,
true);
2691 return CreateShadowCast(IRB, S2, T,
true);
2708 void handleVectorShiftIntrinsic(
IntrinsicInst &I,
bool Variable) {
2713 Value *S1 = getShadow(&I, 0);
2714 Value *S2 = getShadow(&I, 1);
2715 Value *S2Conv = Variable ? VariableShadowExtend(IRB, S2)
2716 : Lower64ShadowExtend(IRB, S2, getShadowTy(&I));
2720 {IRB.CreateBitCast(S1, V1->
getType()), V2});
2721 Shift = IRB.CreateBitCast(Shift, getShadowTy(&I));
2722 setShadow(&I, IRB.CreateOr(Shift, S2Conv));
2723 setOriginForNaryOp(I);
2727 Type *getMMXVectorTy(
unsigned EltSizeInBits) {
2728 const unsigned X86_MMXSizeInBits = 64;
2729 assert(EltSizeInBits != 0 && (X86_MMXSizeInBits % EltSizeInBits) == 0 &&
2730 "Illegal MMX vector element size");
2732 X86_MMXSizeInBits / EltSizeInBits);
2739 case Intrinsic::x86_sse2_packsswb_128:
2740 case Intrinsic::x86_sse2_packuswb_128:
2741 return Intrinsic::x86_sse2_packsswb_128;
2743 case Intrinsic::x86_sse2_packssdw_128:
2744 case Intrinsic::x86_sse41_packusdw:
2745 return Intrinsic::x86_sse2_packssdw_128;
2747 case Intrinsic::x86_avx2_packsswb:
2748 case Intrinsic::x86_avx2_packuswb:
2749 return Intrinsic::x86_avx2_packsswb;
2751 case Intrinsic::x86_avx2_packssdw:
2752 case Intrinsic::x86_avx2_packusdw:
2753 return Intrinsic::x86_avx2_packssdw;
2755 case Intrinsic::x86_mmx_packsswb:
2756 case Intrinsic::x86_mmx_packuswb:
2757 return Intrinsic::x86_mmx_packsswb;
2759 case Intrinsic::x86_mmx_packssdw:
2760 return Intrinsic::x86_mmx_packssdw;
2773 void handleVectorPackIntrinsic(
IntrinsicInst &I,
unsigned EltSizeInBits = 0) {
2777 Value *S1 = getShadow(&I, 0);
2778 Value *S2 = getShadow(&I, 1);
2784 Type *T = isX86_MMX ? getMMXVectorTy(EltSizeInBits) : S1->
getType();
2803 IRB.
CreateCall(ShadowFn, {S1_ext, S2_ext},
"_msprop_vector_pack");
2806 setOriginForNaryOp(I);
2811 const unsigned SignificantBitsPerResultElement = 16;
2814 unsigned ZeroBitsPerResultElement =
2818 Value *S = IRB.
CreateOr(getShadow(&I, 0), getShadow(&I, 1));
2822 S = IRB.
CreateLShr(S, ZeroBitsPerResultElement);
2825 setOriginForNaryOp(I);
2830 unsigned EltSizeInBits = 0) {
2832 Type *ResTy = isX86_MMX ? getMMXVectorTy(EltSizeInBits * 2) : I.
getType();
2834 Value *S = IRB.
CreateOr(getShadow(&I, 0), getShadow(&I, 1));
2840 setOriginForNaryOp(I);
2848 Type *ResTy = getShadowTy(&I);
2849 Value *S0 = IRB.
CreateOr(getShadow(&I, 0), getShadow(&I, 1));
2853 setOriginForNaryOp(I);
2861 Value *S0 = IRB.
CreateOr(getShadow(&I, 0), getShadow(&I, 1));
2862 Value *S = LowerElementShadowExtend(IRB, S0, getShadowTy(&I));
2864 setOriginForNaryOp(I);
2872 getShadowOriginPtr(Addr, IRB, Ty,
Align::None(),
true)
2879 insertShadowCheck(Addr, &I);
2883 if (!InsertChecks)
return;
2889 Value *ShadowPtr, *OriginPtr;
2890 std::tie(ShadowPtr, OriginPtr) =
2891 getShadowOriginPtr(Addr, IRB, Ty, Alignment,
false);
2894 insertShadowCheck(Addr, &I);
2898 Value *Origin = MS.TrackOrigins ? IRB.
CreateLoad(MS.OriginTy, OriginPtr)
2900 insertShadowCheck(Shadow, Origin, &I);
2910 Value *Shadow = getShadow(V);
2914 std::tie(ShadowPtr, OriginPtr) = getShadowOriginPtr(
2915 Addr, IRB, Shadow->
getType(), Alignment,
true);
2918 insertShadowCheck(Addr, &I);
2921 insertShadowCheck(Mask, &I);
2927 if (MS.TrackOrigins) {
2929 paintOrigin(IRB, getOrigin(V), OriginPtr,
2930 DL.getTypeStoreSize(Shadow->
getType()),
2931 llvm::max(Alignment, kMinOriginAlignment));
2943 Type *ShadowTy = getShadowTy(&I);
2944 Value *ShadowPtr, *OriginPtr;
2945 if (PropagateShadow) {
2946 std::tie(ShadowPtr, OriginPtr) =
2947 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment,
false);
2949 ShadowPtr, Alignment ? Alignment->value() : 0,
Mask,
2950 getShadow(PassThru),
"_msmaskedld"));
2952 setShadow(&I, getCleanShadow(&I));
2956 insertShadowCheck(Addr, &I);
2957 insertShadowCheck(Mask, &I);
2960 if (MS.TrackOrigins) {
2961 if (PropagateShadow) {
2977 getOrigin(PassThru), IRB.
CreateLoad(MS.OriginTy, OriginPtr));
2979 setOrigin(&I, Origin);
2981 setOrigin(&I, getCleanOrigin());
2994 Type *ShadowTy = getShadowTy(&I);
2997 Value *SMask = getShadow(&I, 1);
3005 setOriginForNaryOp(I);
3010 for (
unsigned X = OddElements ? 1 : 0;
X <
Width;
X += 2) {
3028 Type *ShadowTy = getShadowTy(&I);
3031 "pclmul 3rd operand must be a constant");
3032 unsigned Imm = cast<ConstantInt>(I.
getArgOperand(2))->getZExtValue();
3035 getPclmulMask(IRB, Width, Imm & 0x01));
3038 getPclmulMask(IRB, Width, Imm & 0x10));
3039 ShadowAndOriginCombiner SOC(
this, IRB);
3040 SOC.Add(Shuf0, getOrigin(&I, 0));
3041 SOC.Add(Shuf1, getOrigin(&I, 1));
3047 case Intrinsic::lifetime_start:
3048 handleLifetimeStart(I);
3050 case Intrinsic::launder_invariant_group:
3051 case Intrinsic::strip_invariant_group:
3052 handleInvariantGroup(I);
3054 case Intrinsic::bswap:
3057 case Intrinsic::masked_store:
3058 handleMaskedStore(I);
3060 case Intrinsic::masked_load:
3061 handleMaskedLoad(I);
3063 case Intrinsic::x86_sse_stmxcsr:
3066 case Intrinsic::x86_sse_ldmxcsr:
3069 case Intrinsic::x86_avx512_vcvtsd2usi64:
3070 case Intrinsic::x86_avx512_vcvtsd2usi32:
3071 case Intrinsic::x86_avx512_vcvtss2usi64:
3072 case Intrinsic::x86_avx512_vcvtss2usi32:
3073 case Intrinsic::x86_avx512_cvttss2usi64:
3074 case Intrinsic::x86_avx512_cvttss2usi:
3075 case Intrinsic::x86_avx512_cvttsd2usi64:
3076 case Intrinsic::x86_avx512_cvttsd2usi:
3077 case Intrinsic::x86_avx512_cvtusi2ss:
3078 case Intrinsic::x86_avx512_cvtusi642sd:
3079 case Intrinsic::x86_avx512_cvtusi642ss:
3080 case Intrinsic::x86_sse2_cvtsd2si64:
3081 case Intrinsic::x86_sse2_cvtsd2si:
3082 case Intrinsic::x86_sse2_cvtsd2ss:
3083 case Intrinsic::x86_sse2_cvttsd2si64:
3084 case Intrinsic::x86_sse2_cvttsd2si:
3085 case Intrinsic::x86_sse_cvtss2si64:
3086 case Intrinsic::x86_sse_cvtss2si:
3087 case Intrinsic::x86_sse_cvttss2si64:
3088 case Intrinsic::x86_sse_cvttss2si:
3089 handleVectorConvertIntrinsic(I, 1);
3091 case Intrinsic::x86_sse_cvtps2pi:
3092 case Intrinsic::x86_sse_cvttps2pi:
3093 handleVectorConvertIntrinsic(I, 2);
3096 case Intrinsic::x86_avx512_psll_w_512:
3097 case Intrinsic::x86_avx512_psll_d_512:
3098 case Intrinsic::x86_avx512_psll_q_512:
3099 case Intrinsic::x86_avx512_pslli_w_512:
3100 case Intrinsic::x86_avx512_pslli_d_512:
3101 case Intrinsic::x86_avx512_pslli_q_512:
3102 case Intrinsic::x86_avx512_psrl_w_512:
3103 case Intrinsic::x86_avx512_psrl_d_512:
3104 case Intrinsic::x86_avx512_psrl_q_512:
3105 case Intrinsic::x86_avx512_psra_w_512:
3106 case Intrinsic::x86_avx512_psra_d_512:
3107 case Intrinsic::x86_avx512_psra_q_512:
3108 case Intrinsic::x86_avx512_psrli_w_512:
3109 case Intrinsic::x86_avx512_psrli_d_512:
3110 case Intrinsic::x86_avx512_psrli_q_512:
3111 case Intrinsic::x86_avx512_psrai_w_512:
3112 case Intrinsic::x86_avx512_psrai_d_512:
3113 case Intrinsic::x86_avx512_psrai_q_512:
3114 case Intrinsic::x86_avx512_psra_q_256:
3115 case Intrinsic::x86_avx512_psra_q_128:
3116 case Intrinsic::x86_avx512_psrai_q_256:
3117 case Intrinsic::x86_avx512_psrai_q_128:
3118 case Intrinsic::x86_avx2_psll_w:
3119 case Intrinsic::x86_avx2_psll_d:
3120 case Intrinsic::x86_avx2_psll_q:
3121 case Intrinsic::x86_avx2_pslli_w:
3122 case Intrinsic::x86_avx2_pslli_d:
3123 case Intrinsic::x86_avx2_pslli_q:
3124 case Intrinsic::x86_avx2_psrl_w:
3125 case Intrinsic::x86_avx2_psrl_d:
3126 case Intrinsic::x86_avx2_psrl_q:
3127 case Intrinsic::x86_avx2_psra_w:
3128 case Intrinsic::x86_avx2_psra_d:
3129 case Intrinsic::x86_avx2_psrli_w:
3130 case Intrinsic::x86_avx2_psrli_d:
3131 case Intrinsic::x86_avx2_psrli_q:
3132 case Intrinsic::x86_avx2_psrai_w:
3133 case Intrinsic::x86_avx2_psrai_d:
3134 case Intrinsic::x86_sse2_psll_w:
3135 case Intrinsic::x86_sse2_psll_d:
3136 case Intrinsic::x86_sse2_psll_q:
3137 case Intrinsic::x86_sse2_pslli_w:
3138 case Intrinsic::x86_sse2_pslli_d:
3139 case Intrinsic::x86_sse2_pslli_q:
3140 case Intrinsic::x86_sse2_psrl_w:
3141 case Intrinsic::x86_sse2_psrl_d:
3142 case Intrinsic::x86_sse2_psrl_q:
3143 case Intrinsic::x86_sse2_psra_w:
3144 case Intrinsic::x86_sse2_psra_d:
3145 case Intrinsic::x86_sse2_psrli_w:
3146 case Intrinsic::x86_sse2_psrli_d:
3147 case Intrinsic::x86_sse2_psrli_q:
3148 case Intrinsic::x86_sse2_psrai_w:
3149 case Intrinsic::x86_sse2_psrai_d:
3150 case Intrinsic::x86_mmx_psll_w:
3151 case Intrinsic::x86_mmx_psll_d:
3152 case Intrinsic::x86_mmx_psll_q:
3153 case Intrinsic::x86_mmx_pslli_w:
3154 case Intrinsic::x86_mmx_pslli_d:
3155 case Intrinsic::x86_mmx_pslli_q:
3156 case Intrinsic::x86_mmx_psrl_w:
3157 case Intrinsic::x86_mmx_psrl_d:
3158 case Intrinsic::x86_mmx_psrl_q:
3159 case Intrinsic::x86_mmx_psra_w:
3160 case Intrinsic::x86_mmx_psra_d:
3161 case Intrinsic::x86_mmx_psrli_w:
3162 case Intrinsic::x86_mmx_psrli_d:
3163 case Intrinsic::x86_mmx_psrli_q:
3164 case Intrinsic::x86_mmx_psrai_w:
3165 case Intrinsic::x86_mmx_psrai_d:
3166 handleVectorShiftIntrinsic(I,
false);
3168 case Intrinsic::x86_avx2_psllv_d:
3169 case Intrinsic::x86_avx2_psllv_d_256:
3170 case Intrinsic::x86_avx512_psllv_d_512:
3171 case Intrinsic::x86_avx2_psllv_q:
3172 case Intrinsic::x86_avx2_psllv_q_256:
3173 case Intrinsic::x86_avx512_psllv_q_512:
3174 case Intrinsic::x86_avx2_psrlv_d:
3175 case Intrinsic::x86_avx2_psrlv_d_256:
3176 case Intrinsic::x86_avx512_psrlv_d_512:
3177 case Intrinsic::x86_avx2_psrlv_q:
3178 case Intrinsic::x86_avx2_psrlv_q_256:
3179 case Intrinsic::x86_avx512_psrlv_q_512:
3180 case Intrinsic::x86_avx2_psrav_d:
3181 case Intrinsic::x86_avx2_psrav_d_256:
3182 case Intrinsic::x86_avx512_psrav_d_512:
3183 case Intrinsic::x86_avx512_psrav_q_128:
3184 case Intrinsic::x86_avx512_psrav_q_256:
3185 case Intrinsic::x86_avx512_psrav_q_512:
3186 handleVectorShiftIntrinsic(I,
true);
3189 case Intrinsic::x86_sse2_packsswb_128:
3190 case Intrinsic::x86_sse2_packssdw_128:
3191 case Intrinsic::x86_sse2_packuswb_128:
3192 case Intrinsic::x86_sse41_packusdw:
3193 case Intrinsic::x86_avx2_packsswb:
3194 case Intrinsic::x86_avx2_packssdw:
3195 case Intrinsic::x86_avx2_packuswb:
3196 case Intrinsic::x86_avx2_packusdw:
3197 handleVectorPackIntrinsic(I);
3200 case Intrinsic::x86_mmx_packsswb:
3201 case Intrinsic::x86_mmx_packuswb:
3202 handleVectorPackIntrinsic(I, 16);
3205 case Intrinsic::x86_mmx_packssdw:
3206 handleVectorPackIntrinsic(I, 32);
3209 case Intrinsic::x86_mmx_psad_bw:
3210 case Intrinsic::x86_sse2_psad_bw:
3211 case Intrinsic::x86_avx2_psad_bw:
3212 handleVectorSadIntrinsic(I);
3215 case Intrinsic::x86_sse2_pmadd_wd:
3216 case Intrinsic::x86_avx2_pmadd_wd:
3217 case Intrinsic::x86_ssse3_pmadd_ub_sw_128:
3218 case Intrinsic::x86_avx2_pmadd_ub_sw:
3219 handleVectorPmaddIntrinsic(I);
3222 case Intrinsic::x86_ssse3_pmadd_ub_sw:
3223 handleVectorPmaddIntrinsic(I, 8);
3226 case Intrinsic::x86_mmx_pmadd_wd:
3227 handleVectorPmaddIntrinsic(I, 16);
3230 case Intrinsic::x86_sse_cmp_ss:
3231 case Intrinsic::x86_sse2_cmp_sd:
3232 case Intrinsic::x86_sse_comieq_ss:
3233 case Intrinsic::x86_sse_comilt_ss:
3234 case Intrinsic::x86_sse_comile_ss:
3235 case Intrinsic::x86_sse_comigt_ss:
3236 case Intrinsic::x86_sse_comige_ss:
3237 case Intrinsic::x86_sse_comineq_ss:
3238 case Intrinsic::x86_sse_ucomieq_ss:
3239 case Intrinsic::x86_sse_ucomilt_ss:
3240 case Intrinsic::x86_sse_ucomile_ss:
3241 case Intrinsic::x86_sse_ucomigt_ss:
3242 case Intrinsic::x86_sse_ucomige_ss:
3243 case Intrinsic::x86_sse_ucomineq_ss:
3244 case Intrinsic::x86_sse2_comieq_sd:
3245 case Intrinsic::x86_sse2_comilt_sd:
3246 case Intrinsic::x86_sse2_comile_sd:
3247 case Intrinsic::x86_sse2_comigt_sd:
3248 case Intrinsic::x86_sse2_comige_sd:
3249 case Intrinsic::x86_sse2_comineq_sd:
3250 case Intrinsic::x86_sse2_ucomieq_sd:
3251 case Intrinsic::x86_sse2_ucomilt_sd:
3252 case Intrinsic::x86_sse2_ucomile_sd:
3253 case Intrinsic::x86_sse2_ucomigt_sd:
3254 case Intrinsic::x86_sse2_ucomige_sd:
3255 case Intrinsic::x86_sse2_ucomineq_sd:
3256 handleVectorCompareScalarIntrinsic(I);
3259 case Intrinsic::x86_sse_cmp_ps:
3260 case Intrinsic::x86_sse2_cmp_pd:
3264 handleVectorComparePackedIntrinsic(I);
3267 case Intrinsic::x86_bmi_bextr_32:
3268 case Intrinsic::x86_bmi_bextr_64:
3269 case Intrinsic::x86_bmi_bzhi_32:
3270 case Intrinsic::x86_bmi_bzhi_64:
3271 case Intrinsic::x86_bmi_pdep_32:
3272 case Intrinsic::x86_bmi_pdep_64:
3273 case Intrinsic::x86_bmi_pext_32:
3274 case Intrinsic::x86_bmi_pext_64:
3275 handleBmiIntrinsic(I);
3278 case Intrinsic::x86_pclmulqdq:
3279 case Intrinsic::x86_pclmulqdq_256:
3280 case Intrinsic::x86_pclmulqdq_512:
3281 handlePclmulIntrinsic(I);
3284 case Intrinsic::is_constant:
3286 setShadow(&I, getCleanShadow(&I));
3287 setOrigin(&I, getCleanOrigin());
3291 if (!handleUnknownIntrinsic(I))
3292 visitInstruction(I);
3301 "Unknown type of CallSite");
3302 if (CS.
isCallBr() || (CS.
isCall() && cast<CallInst>(&
I)->isInlineAsm())) {
3308 visitAsmInstruction(I);
3310 visitInstruction(I);
3315 assert(!isa<IntrinsicInst>(&I) &&
"intrinsics are handled elsewhere");
3336 unsigned ArgOffset = 0;
3339 ArgIt != End; ++ArgIt) {
3343 LLVM_DEBUG(
dbgs() <<
"Arg " << i <<
" is not sized: " << I <<
"\n");
3351 Value *ArgShadow = getShadow(A);
3352 Value *ArgShadowBase = getShadowPtrForArgument(A, IRB, ArgOffset);
3354 <<
" Shadow: " << *ArgShadow <<
"\n");
3355 bool ArgIsInitialized =
false;
3359 "ByVal argument is not a pointer!");
3361 if (ArgOffset + Size > kParamTLSSize)
break;
3365 Alignment = std::min(*ParamAlignment, kShadowTLSAlignment);
3367 getShadowOriginPtr(A, IRB, IRB.
getInt8Ty(), Alignment,
3371 Store = IRB.
CreateMemCpy(ArgShadowBase, Alignment, AShadowPtr,
3376 if (ArgOffset + Size > kParamTLSSize)
break;
3378 kShadowTLSAlignment.
value());
3380 if (Cst && Cst->
isNullValue()) ArgIsInitialized =
true;
3382 if (MS.TrackOrigins && !ArgIsInitialized)
3384 getOriginPtrForArgument(A, IRB, ArgOffset));
3386 assert(Size != 0 && Store !=
nullptr);
3388 ArgOffset +=
alignTo(Size, 8);
3394 VAHelper->visitCallSite(CS, IRB);
3400 if (CS.
isCall() && cast<CallInst>(&
I)->isMustTailCall())
return;
3403 Value *
Base = getShadowPtrForRetval(&I, IRBBefore);
3405 kShadowTLSAlignment.
value());
3411 BasicBlock *NormalDest = cast<InvokeInst>(&
I)->getNormalDest();
3416 setShadow(&I, getCleanShadow(&I));
3417 setOrigin(&I, getCleanOrigin());
3424 "Could not find insertion point for retval shadow load");
3427 Value *RetvalShadow = IRBAfter.CreateAlignedLoad(
3428 getShadowTy(&I), getShadowPtrForRetval(&I, IRBAfter),
3429 kShadowTLSAlignment.
value(),
"_msret");
3430 setShadow(&I, RetvalShadow);
3431 if (MS.TrackOrigins)
3432 setOrigin(&I, IRBAfter.CreateLoad(MS.OriginTy,
3433 getOriginPtrForRetval(IRBAfter)));
3436 bool isAMustTailRetVal(
Value *RetVal) {
3437 if (
auto *I = dyn_cast<BitCastInst>(RetVal)) {
3440 if (
auto *I = dyn_cast<CallInst>(RetVal)) {
3449 if (!RetVal)
return;
3451 if (isAMustTailRetVal(RetVal))
return;
3452 Value *ShadowPtr = getShadowPtrForRetval(RetVal, IRB);
3453 if (CheckReturnValue) {
3454 insertShadowCheck(RetVal, &I);
3455 Value *Shadow = getCleanShadow(RetVal);
3458 Value *Shadow = getShadow(RetVal);
3460 if (MS.TrackOrigins)
3461 IRB.
CreateStore(getOrigin(RetVal), getOriginPtrForRetval(IRB));
3465 void visitPHINode(
PHINode &I) {
3467 if (!PropagateShadow) {
3468 setShadow(&I, getCleanShadow(&I));
3469 setOrigin(&I, getCleanOrigin());
3476 if (MS.TrackOrigins)
3491 StackDescription.
str());
3497 {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len});
3499 Value *ShadowBase, *OriginBase;
3500 std::tie(ShadowBase, OriginBase) = getShadowOriginPtr(
3508 if (PoisonStack && MS.TrackOrigins) {
3509 Value *Descr = getLocalVarDescription(I);
3511 {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len,
3512 IRB.CreatePointerCast(Descr, IRB.getInt8PtrTy()),
3513 IRB.CreatePointerCast(&F, MS.IntptrTy)});
3518 Value *Descr = getLocalVarDescription(I);
3521 {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len,
3522 IRB.CreatePointerCast(Descr, IRB.getInt8PtrTy())});
3525 {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len});
3539 if (MS.CompileKernel)
3540 poisonAllocaKmsan(I, IRB, Len);
3542 poisonAllocaUserspace(I, IRB, Len);
3546 setShadow(&I, getCleanShadow(&I));
3547 setOrigin(&I, getCleanOrigin());
3559 Value *Sb = getShadow(B);
3560 Value *Sc = getShadow(C);
3561 Value *Sd = getShadow(D);
3570 Sa1 = getPoisonedShadow(getShadowTy(I.
getType()));
3578 C = CreateAppToShadowCast(IRB, C);
3579 D = CreateAppToShadowCast(IRB, D);
3586 if (MS.TrackOrigins) {
3608 setShadow(&I, getCleanShadow(&I));
3609 setOrigin(&I, getCleanOrigin());
3613 setShadow(&I, getCleanShadow(&I));
3614 setOrigin(&I, getCleanOrigin());
3618 setShadow(&I, getCleanShadow(&I));
3619 setOrigin(&I, getCleanOrigin());
3630 Value *AggShadow = getShadow(Agg);
3634 setShadow(&I, ResShadow);
3635 setOriginForNaryOp(I);
3648 setOriginForNaryOp(I);
3652 if (
CallInst *CI = dyn_cast<CallInst>(&I)) {
3653 errs() <<
"ZZZ call " << CI->getCalledFunction()->getName() <<
"\n";
3657 errs() <<
"QQQ " << I <<
"\n";
3683 insertShadowCheck(Operand, &I);
3694 IRB.
CreateCall(MS.MsanInstrumentAsmStoreFn, {Ptr, SizeVal});
3699 int NumRetOutputs = 0;
3706 NumRetOutputs =
ST->getNumElements();
3711 for (
size_t i = 0, n = Constraints.size(); i < n; i++) {
3713 switch (Info.
Type) {
3721 return NumOutputs - NumRetOutputs;
3744 int OutputArgs = getNumOutputArgs(IA, CB);
3750 for (
int i = OutputArgs; i < NumOperands; i++) {
3752 instrumentAsmArgument(Operand, I, IRB, DL,
false);
3757 for (
int i = 0; i < OutputArgs; i++) {
3759 instrumentAsmArgument(Operand, I, IRB, DL,
true);
3762 setShadow(&I, getCleanShadow(&I));
3763 setOrigin(&I, getCleanOrigin());
3774 insertShadowCheck(Operand, &I);
3776 setShadow(&I, getCleanShadow(&I));
3777 setOrigin(&I, getCleanOrigin());
3782 struct VarArgAMD64Helper :
public VarArgHelper {
3785 static const unsigned AMD64GpEndOffset = 48;
3786 static const unsigned AMD64FpEndOffsetSSE = 176;
3788 static const unsigned AMD64FpEndOffsetNoSSE = AMD64GpEndOffset;
3790 unsigned AMD64FpEndOffset;
3792 MemorySanitizer &MS;
3793 MemorySanitizerVisitor &MSV;
3794 Value *VAArgTLSCopy =
nullptr;
3795 Value *VAArgTLSOriginCopy =
nullptr;
3796 Value *VAArgOverflowSize =
nullptr;
3800 enum ArgKind { AK_GeneralPurpose, AK_FloatingPoint, AK_Memory };
3802 VarArgAMD64Helper(
Function &F, MemorySanitizer &MS,
3803 MemorySanitizerVisitor &MSV)
3804 :
F(F), MS(MS), MSV(MSV) {
3805 AMD64FpEndOffset = AMD64FpEndOffsetSSE;
3807 if (Attr.isStringAttribute() &&
3808 (Attr.getKindAsString() ==
"target-features")) {
3809 if (Attr.getValueAsString().contains(
"-sse"))
3810 AMD64FpEndOffset = AMD64FpEndOffsetNoSSE;
3816 ArgKind classifyArgument(
Value* arg) {
3820 return AK_FloatingPoint;
3822 return AK_GeneralPurpose;
3824 return AK_GeneralPurpose;
3837 unsigned GpOffset = 0;
3838 unsigned FpOffset = AMD64GpEndOffset;
3839 unsigned OverflowOffset = AMD64FpEndOffset;
3842 ArgIt != End; ++ArgIt) {
3846 bool IsByVal = CS.
paramHasAttr(ArgNo, Attribute::ByVal);
3856 Value *ShadowBase = getShadowPtrForVAArgument(
3857 RealTy, IRB, OverflowOffset,
alignTo(ArgSize, 8));
3858 Value *OriginBase =
nullptr;
3859 if (MS.TrackOrigins)
3860 OriginBase = getOriginPtrForVAArgument(RealTy, IRB, OverflowOffset);
3861 OverflowOffset +=
alignTo(ArgSize, 8);
3864 Value *ShadowPtr, *OriginPtr;
3865 std::tie(ShadowPtr, OriginPtr) =
3869 IRB.
CreateMemCpy(ShadowBase, kShadowTLSAlignment, ShadowPtr,
3870 kShadowTLSAlignment, ArgSize);
3871 if (MS.TrackOrigins)
3872 IRB.
CreateMemCpy(OriginBase, kShadowTLSAlignment, OriginPtr,
3873 kShadowTLSAlignment, ArgSize);
3875 ArgKind AK = classifyArgument(A);
3876 if (AK == AK_GeneralPurpose && GpOffset >= AMD64GpEndOffset)
3878 if (AK == AK_FloatingPoint && FpOffset >= AMD64FpEndOffset)
3880 Value *ShadowBase, *OriginBase =
nullptr;
3882 case AK_GeneralPurpose:
3884 getShadowPtrForVAArgument(A->
getType(), IRB, GpOffset, 8);
3885 if (MS.TrackOrigins)
3887 getOriginPtrForVAArgument(A->
getType(), IRB, GpOffset);
3890 case AK_FloatingPoint:
3892 getShadowPtrForVAArgument(A->
getType(), IRB, FpOffset, 16);
3893 if (MS.TrackOrigins)
3895 getOriginPtrForVAArgument(A->
getType(), IRB, FpOffset);
3903 getShadowPtrForVAArgument(A->
getType(), IRB, OverflowOffset, 8);
3904 if (MS.TrackOrigins)
3906 getOriginPtrForVAArgument(A->
getType(), IRB, OverflowOffset);
3907 OverflowOffset +=
alignTo(ArgSize, 8);
3916 Value *Shadow = MSV.getShadow(A);
3918 if (MS.TrackOrigins) {
3919 Value *Origin = MSV.getOrigin(A);
3921 MSV.paintOrigin(IRB, Origin, OriginBase, StoreSize,
3922 std::max(kShadowTLSAlignment, kMinOriginAlignment));
3928 IRB.
CreateStore(OverflowSize, MS.VAArgOverflowSizeTLS);
3933 unsigned ArgOffset,
unsigned ArgSize) {
3935 if (ArgOffset + ArgSize > kParamTLSSize)
3957 Value *ShadowPtr, *OriginPtr;
3959 std::tie(ShadowPtr, OriginPtr) =
3960 MSV.getShadowOriginPtr(VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
3966 24, Alignment,
false);
3974 VAStartInstrumentationList.
push_back(&I);
3975 unpoisonVAListTagForInst(I);
3978 void visitVACopyInst(
VACopyInst &I)
override {
3980 unpoisonVAListTagForInst(I);
3983 void finalizeInstrumentation()
override {
3984 assert(!VAArgOverflowSize && !VAArgTLSCopy &&
3985 "finalizeInstrumentation called twice");
3986 if (!VAStartInstrumentationList.
empty()) {
3989 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
3997 if (MS.TrackOrigins) {
4000 Align(8), CopySize);
4006 for (
size_t i = 0, n = VAStartInstrumentationList.
size(); i < n; i++) {
4007 CallInst *OrigInst = VAStartInstrumentationList[i];
4016 Value *RegSaveAreaPtr =
4017 IRB.
CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
4018 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
4020 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
4021 MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4023 IRB.
CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
4025 if (MS.TrackOrigins)
4026 IRB.
CreateMemCpy(RegSaveAreaOriginPtr, Alignment, VAArgTLSOriginCopy,
4027 Alignment, AMD64FpEndOffset);
4033 Value *OverflowArgAreaPtr =
4034 IRB.
CreateLoad(OverflowArgAreaPtrTy, OverflowArgAreaPtrPtr);
4035 Value *OverflowArgAreaShadowPtr, *OverflowArgAreaOriginPtr;
4036 std::tie(OverflowArgAreaShadowPtr, OverflowArgAreaOriginPtr) =
4037 MSV.getShadowOriginPtr(OverflowArgAreaPtr, IRB, IRB.
getInt8Ty(),
4041 IRB.
CreateMemCpy(OverflowArgAreaShadowPtr, Alignment, SrcPtr, Alignment,
4043 if (MS.TrackOrigins) {
4046 IRB.
CreateMemCpy(OverflowArgAreaOriginPtr, Alignment, SrcPtr, Alignment,
4054 struct VarArgMIPS64Helper :
public VarArgHelper {
4056 MemorySanitizer &MS;
4057 MemorySanitizerVisitor &MSV;
4058 Value *VAArgTLSCopy =
nullptr;
4059 Value *VAArgSize =
nullptr;
4063 VarArgMIPS64Helper(
Function &F, MemorySanitizer &MS,
4064 MemorySanitizerVisitor &MSV) :
F(F), MS(MS), MSV(MSV) {}
4067 unsigned VAArgOffset = 0;
4071 ArgIt != End; ++ArgIt) {
4080 VAArgOffset += (8 - ArgSize);
4082 Base = getShadowPtrForVAArgument(A->getType(), IRB, VAArgOffset, ArgSize);
4083 VAArgOffset += ArgSize;
4084 VAArgOffset =
alignTo(VAArgOffset, 8);
4088 kShadowTLSAlignment.
value());
4094 IRB.
CreateStore(TotalVAArgSize, MS.VAArgOverflowSizeTLS);
4099 unsigned ArgOffset,
unsigned ArgSize) {
4101 if (ArgOffset + ArgSize > kParamTLSSize)
4111 VAStartInstrumentationList.
push_back(&I);
4113 Value *ShadowPtr, *OriginPtr;
4115 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4116 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4118 8, Alignment,
false);
4121 void visitVACopyInst(
VACopyInst &I)
override {
4123 VAStartInstrumentationList.
push_back(&I);
4125 Value *ShadowPtr, *OriginPtr;
4127 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4128 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4130 8, Alignment,
false);
4133 void finalizeInstrumentation()
override {
4134 assert(!VAArgSize && !VAArgTLSCopy &&
4135 "finalizeInstrumentation called twice");
4136 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
4141 if (!VAStartInstrumentationList.
empty()) {
4150 for (
size_t i = 0, n = VAStartInstrumentationList.
size(); i < n; i++) {
4151 CallInst *OrigInst = VAStartInstrumentationList[i];
4155 Value *RegSaveAreaPtrPtr =
4158 Value *RegSaveAreaPtr =
4159 IRB.
CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
4160 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
4162 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
4163 MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4165 IRB.
CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
4172 struct VarArgAArch64Helper :
public VarArgHelper {
4173 static const unsigned kAArch64GrArgSize = 64;
4174 static const unsigned kAArch64VrArgSize = 128;
4176 static const unsigned AArch64GrBegOffset = 0;
4177 static const unsigned AArch64GrEndOffset = kAArch64GrArgSize;
4179 static const unsigned AArch64VrBegOffset = AArch64GrEndOffset;
4180 static const unsigned AArch64VrEndOffset = AArch64VrBegOffset
4181 + kAArch64VrArgSize;
4182 static const unsigned AArch64VAEndOffset = AArch64VrEndOffset;
4185 MemorySanitizer &MS;
4186 MemorySanitizerVisitor &MSV;
4187 Value *VAArgTLSCopy =
nullptr;
4188 Value *VAArgOverflowSize =
nullptr;
4192 enum ArgKind { AK_GeneralPurpose, AK_FloatingPoint, AK_Memory };
4194 VarArgAArch64Helper(
Function &F, MemorySanitizer &MS,
4195 MemorySanitizerVisitor &MSV) :
F(F), MS(MS), MSV(MSV) {}
4197 ArgKind classifyArgument(
Value* arg) {
4200 return AK_FloatingPoint;
4203 return AK_GeneralPurpose;
4217 unsigned GrOffset = AArch64GrBegOffset;
4218 unsigned VrOffset = AArch64VrBegOffset;
4219 unsigned OverflowOffset = AArch64VAEndOffset;
4223 ArgIt != End; ++ArgIt) {
4227 ArgKind AK = classifyArgument(A);
4228 if (AK == AK_GeneralPurpose && GrOffset >= AArch64GrEndOffset)
4230 if (AK == AK_FloatingPoint && VrOffset >= AArch64VrEndOffset)
4234 case AK_GeneralPurpose:
4235 Base = getShadowPtrForVAArgument(A->
getType(), IRB, GrOffset, 8);
4238 case AK_FloatingPoint:
4239 Base = getShadowPtrForVAArgument(A->
getType(), IRB, VrOffset, 8);
4248 Base = getShadowPtrForVAArgument(A->
getType(), IRB, OverflowOffset,
4250 OverflowOffset +=
alignTo(ArgSize, 8);
4260 kShadowTLSAlignment.
value());
4264 IRB.
CreateStore(OverflowSize, MS.VAArgOverflowSizeTLS);
4269 unsigned ArgOffset,
unsigned ArgSize) {
4271 if (ArgOffset + ArgSize > kParamTLSSize)
4281 VAStartInstrumentationList.
push_back(&I);
4283 Value *ShadowPtr, *OriginPtr;
4285 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4286 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4288 32, Alignment,
false);
4291 void visitVACopyInst(
VACopyInst &I)
override {
4293 VAStartInstrumentationList.
push_back(&I);
4295 Value *ShadowPtr, *OriginPtr;
4297 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4298 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4300 32, Alignment,
false);
4305 Value *SaveAreaPtrPtr =
4315 Value *SaveAreaPtr =
4321 return IRB.
CreateSExt(SaveArea32, MS.IntptrTy);
4324 void finalizeInstrumentation()
override {
4325 assert(!VAArgOverflowSize && !VAArgTLSCopy &&
4326 "finalizeInstrumentation called twice");
4327 if (!VAStartInstrumentationList.
empty()) {
4330 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
4345 for (
size_t i = 0, n = VAStartInstrumentationList.
size(); i < n; i++) {
4346 CallInst *OrigInst = VAStartInstrumentationList[i];
4365 Value *StackSaveAreaPtr = getVAField64(IRB, VAListTag, 0);
4368 Value *GrTopSaveAreaPtr = getVAField64(IRB, VAListTag, 8);
4369 Value *GrOffSaveArea = getVAField32(IRB, VAListTag, 24);
4371 Value *GrRegSaveAreaPtr = IRB.
CreateAdd(GrTopSaveAreaPtr, GrOffSaveArea);
4374 Value *VrTopSaveAreaPtr = getVAField64(IRB, VAListTag, 16);
4375 Value *VrOffSaveArea = getVAField32(IRB, VAListTag, 28);
4377 Value *VrRegSaveAreaPtr = IRB.
CreateAdd(VrTopSaveAreaPtr, VrOffSaveArea);
4383 Value *GrRegSaveAreaShadowPtrOff =
4384 IRB.
CreateAdd(GrArgSize, GrOffSaveArea);
4386 Value *GrRegSaveAreaShadowPtr =
4387 MSV.getShadowOriginPtr(GrRegSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4392 GrRegSaveAreaShadowPtrOff);
4393 Value *GrCopySize = IRB.
CreateSub(GrArgSize, GrRegSaveAreaShadowPtrOff);
4399 Value *VrRegSaveAreaShadowPtrOff =
4400 IRB.
CreateAdd(VrArgSize, VrOffSaveArea);
4402 Value *VrRegSaveAreaShadowPtr =
4403 MSV.getShadowOriginPtr(VrRegSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4411 VrRegSaveAreaShadowPtrOff);
4412 Value *VrCopySize = IRB.
CreateSub(VrArgSize, VrRegSaveAreaShadowPtrOff);
4418 Value *StackSaveAreaShadowPtr =
4419 MSV.getShadowOriginPtr(StackSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4423 Value *StackSrcPtr =
4428 Align(16), VAArgOverflowSize);
4434 struct VarArgPowerPC64Helper :
public VarArgHelper {
4436 MemorySanitizer &MS;
4437 MemorySanitizerVisitor &MSV;
4438 Value *VAArgTLSCopy =
nullptr;
4439 Value *VAArgSize =
nullptr;
4443 VarArgPowerPC64Helper(
Function &F, MemorySanitizer &MS,
4444 MemorySanitizerVisitor &MSV) :
F(F), MS(MS), MSV(MSV) {}
4463 unsigned VAArgOffset = VAArgBase;
4466 ArgIt != End; ++ArgIt) {
4470 bool IsByVal = CS.
paramHasAttr(ArgNo, Attribute::ByVal);
4478 VAArgOffset =
alignTo(VAArgOffset, ArgAlign);
4480 Value *
Base = getShadowPtrForVAArgument(
4481 RealTy, IRB, VAArgOffset - VAArgBase, ArgSize);
4483 Value *AShadowPtr, *AOriginPtr;
4484 std::tie(AShadowPtr, AOriginPtr) =
4485 MSV.getShadowOriginPtr(A, IRB, IRB.
getInt8Ty(),
4488 IRB.
CreateMemCpy(Base, kShadowTLSAlignment, AShadowPtr,
4489 kShadowTLSAlignment, ArgSize);
4492 VAArgOffset +=
alignTo(ArgSize, 8);
4496 uint64_t ArgAlign = 8;
4509 VAArgOffset =
alignTo(VAArgOffset, ArgAlign);
4514 VAArgOffset += (8 - ArgSize);
4517 Base = getShadowPtrForVAArgument(A->
getType(), IRB,
4518 VAArgOffset - VAArgBase, ArgSize);
4521 kShadowTLSAlignment.
value());
4523 VAArgOffset += ArgSize;
4524 VAArgOffset =
alignTo(VAArgOffset, 8);
4527 VAArgBase = VAArgOffset;
4531 VAArgOffset - VAArgBase);
4534 IRB.
CreateStore(TotalVAArgSize, MS.VAArgOverflowSizeTLS);
4539 unsigned ArgOffset,
unsigned ArgSize) {
4541 if (ArgOffset + ArgSize > kParamTLSSize)
4551 VAStartInstrumentationList.
push_back(&I);
4553 Value *ShadowPtr, *OriginPtr;
4555 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4556 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4558 8, Alignment,
false);
4561 void visitVACopyInst(
VACopyInst &I)
override {
4564 Value *ShadowPtr, *OriginPtr;
4566 std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
4567 VAListTag, IRB, IRB.
getInt8Ty(), Alignment,
true);
4571 8, Alignment,
false);
4574 void finalizeInstrumentation()
override {
4575 assert(!VAArgSize && !VAArgTLSCopy &&
4576 "finalizeInstrumentation called twice");
4577 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
4582 if (!VAStartInstrumentationList.
empty()) {
4591 for (
size_t i = 0, n = VAStartInstrumentationList.
size(); i < n; i++) {
4592 CallInst *OrigInst = VAStartInstrumentationList[i];
4596 Value *RegSaveAreaPtrPtr =
4599 Value *RegSaveAreaPtr =
4600 IRB.
CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
4601 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
4603 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
4604 MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.
getInt8Ty(),
4606 IRB.
CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
4613 struct VarArgNoOpHelper :
public VarArgHelper {
4614 VarArgNoOpHelper(
Function &
F, MemorySanitizer &MS,
4615 MemorySanitizerVisitor &MSV) {}
4621 void visitVACopyInst(
VACopyInst &I)
override {}
4623 void finalizeInstrumentation()
override {}
4629 MemorySanitizerVisitor &Visitor) {
4634 return new VarArgAMD64Helper(Func, Msan, Visitor);
4635 else if (TargetTriple.isMIPS64())
4636 return new VarArgMIPS64Helper(Func, Msan, Visitor);
4638 return new VarArgAArch64Helper(Func, Msan, Visitor);
4641 return new VarArgPowerPC64Helper(Func, Msan, Visitor);
4643 return new VarArgNoOpHelper(Func, Msan, Visitor);
4650 MemorySanitizerVisitor Visitor(F, *
this, TLI);
4661 return Visitor.runOnFunction();
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Type * getVectorElementType() const
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static const MemoryMapParams Linux_PowerPC64_MemoryMapParams
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name="")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
This class represents an incoming formal argument to a Function.
static const PlatformMemoryMapParams Linux_PowerPC_MemoryMapParams
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
bool doesNotAccessMemory(unsigned OpNo) const
Base class for instruction visitors.
Value * getAggregateOperand()
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Atomic ordering constants.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
BinaryOps getOpcode() const
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
A Module instance is used to store all the information related to an LLVM module. ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, const char *Name)
Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' correctly, instead of converting the strin...
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this rmw instruction.
static const MemoryMapParams Linux_I386_MemoryMapParams
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
An instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
static const MemoryMapParams NetBSD_X86_64_MemoryMapParams
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static cl::opt< bool > ClPoisonStackWithCall("msan-poison-stack-with-call", cl::desc("poison uninitialized stack variables with a call"), cl::Hidden, cl::init(false))
This class represents zero extension of integer types.
static const unsigned kRetvalTLSSize
void push_back(const T &Elt)
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
This class represents a function call, abstracting a target machine's calling convention.
static cl::opt< bool > ClHandleAsmConservative("msan-handle-asm-conservative", cl::desc("conservative handling of inline assembly"), cl::Hidden, cl::init(true))
static PointerType * getInt32PtrTy(LLVMContext &C, unsigned AS=0)
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
const Value * getTrueValue() const
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
Like Internal, but omit from symbol table.
static VarArgHelper * CreateVarArgHelper(Function &Func, MemorySanitizer &Msan, MemorySanitizerVisitor &Visitor)
This instruction constructs a fixed permutation of two input vectors.
static cl::opt< bool > ClWithComdat("msan-with-comdat", cl::desc("Place MSan constructors in comdat sections"), cl::Hidden, cl::init(false))
Externally visible function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
A raw_ostream that writes to an SmallVector or SmallString.
This class wraps the llvm.memset intrinsic.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
static unsigned TypeSizeToSizeIndex(unsigned TypeSize)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a sign extension of integer types.
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
bool isVectorTy() const
True if this is an instance of VectorType.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
bool isMustTailCall() const
static Type * getX86_MMXTy(LLVMContext &C)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
static const MemoryMapParams Linux_AArch64_MemoryMapParams
static cl::opt< bool > ClHandleICmp("msan-handle-icmp", cl::desc("propagate shadow through ICmpEQ and ICmpNE"), cl::Hidden, cl::init(true))
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
FunctionType * getFunctionType() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Value * CreateNot(Value *V, const Twine &Name="")
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Value * getArgOperand(unsigned i) const
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static cl::opt< int > ClPoisonStackPattern("msan-poison-stack-pattern", cl::desc("poison uninitialized stack variables with the given pattern"), cl::Hidden, cl::init(0xff))
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static cl::opt< bool > ClDumpStrictInstructions("msan-dump-strict-instructions", cl::desc("print out instructions with default strict semantics"), cl::Hidden, cl::init(false))
This class represents the LLVM 'select' instruction.
Type * getPointerElementType() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
This is the base class for all instructions that perform data casts.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
'undef' values are things that do not have specified contents.
This class wraps the llvm.memmove intrinsic.
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
static cl::opt< bool > ClCheckAccessAddress("msan-check-access-address", cl::desc("report accesses through a pointer which has poisoned shadow"), cl::Hidden, cl::init(true))
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type representing a pointer to an integer value.
unsigned getArgumentNo(Value::const_user_iterator I) const
Given a value use iterator, returns the argument that corresponds to it.
This file contains the simple types necessary to represent the attributes associated with functions a...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
void setName(const Twine &Name)
Change the name of the value.
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
This file implements a class to represent arbitrary precision integral constant values and operations...
Type * getVoidTy()
Fetch the type representing void.
This class represents a cast from a pointer to an integer.
AtomicOrdering
Atomic ordering for LLVM's memory model.
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
InstrTy * getInstruction() const
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getType() const
All values are typed, get the type of this value.
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
This represents the llvm.va_start intrinsic.
static const char *const kMsanInitName
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
std::string itostr(int64_t X)
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
static cl::opt< int > ClTrackOrigins("msan-track-origins", cl::desc("Track origins (allocation sites) of poisoned memory"), cl::Hidden, cl::init(0))
Track origins of uninitialized values.
Class to represent array types.
std::pair< Function *, FunctionCallee > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, function_ref< void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function lazily.
static cl::opt< uint64_t > ClOriginBase("msan-origin-base", cl::desc("Define custom MSan OriginBase"), cl::Hidden, cl::init(0))
This instruction compares its operands according to the predicate given to the constructor.
static bool isStore(int Opcode)
void setComdat(Comdat *C)
This class represents a no-op cast from one type to another.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Value * getInsertedValueOperand()
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static const unsigned kParamTLSSize
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
ConstraintPrefix Type
Type - The basic type of the constraint: input/output/clobber.
static cl::opt< bool > ClPoisonStack("msan-poison-stack", cl::desc("poison uninitialized stack variables"), cl::Hidden, cl::init(true))
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlignment(Ty), in any case the result is a valid alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
This class represents a truncation of integer types.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
Analysis containing CSE Info
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static const PlatformMemoryMapParams Linux_MIPS_MemoryMapParams
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
The C convention as implemented on Windows/x86-64 and AArch64.
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
static const Align kMinOriginAlignment
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
static const Align kShadowTLSAlignment
This instruction inserts a single (scalar) element into a VectorType value.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Value * getCalledValue() const
static Constant * getOrInsertGlobal(Module &M, StringRef Name, Type *Ty)
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static cl::opt< uint64_t > ClShadowBase("msan-shadow-base", cl::desc("Define custom MSan ShadowBase"), cl::Hidden, cl::init(0))
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
const char * getOpcodeName() const
This is an important base class in LLVM.
Resume the propagation of an exception.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool isPointerTy() const
True if this is an instance of PointerType.
static cl::opt< uint64_t > ClXorMask("msan-xor-mask", cl::desc("Define custom MSan XorMask"), cl::Hidden, cl::init(0))
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
FunctionType * getFunctionType() const
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
int getNumOccurrences() const
Represent the analysis usage information of a pass.
AllocaInst * findAllocaForValue(Value *V, DenseMap< Value *, AllocaInst *> &AllocaForValue)
Finds alloca where the value comes from.
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static const PlatformMemoryMapParams Linux_X86_MemoryMapParams
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
Value * getPointerOperand()
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
self_iterator getIterator()
Class to represent integer types.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
This class represents a cast from an integer to a pointer.
const Value * getCondition() const
static Constant * getAllOnesValue(Type *Ty)
static const PlatformMemoryMapParams Linux_ARM_MemoryMapParams
static const MemoryMapParams FreeBSD_X86_64_MemoryMapParams
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
INITIALIZE_PASS_BEGIN(MemorySanitizerLegacyPass, "msan", "MemorySanitizer: detects uninitialized reads.", false, false) INITIALIZE_PASS_END(MemorySanitizerLegacyPass
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
const Value * getArraySize() const
Get the number of elements allocated.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
static wasm::ValType getType(const TargetRegisterClass *RC)
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
This struct is a compact representation of a valid (non-zero power of two) alignment.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Triple - Helper class for working with autoconf configuration names.
std::vector< ConstraintInfo > ConstraintInfoVector
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Type * getSequentialElementType() const
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Provides information about what library functions are available for the current target.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isAggregateType() const
Return true if the type is an aggregate type.
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask)
Create a call to Masked Store intrinsic.
CHAIN = SC CHAIN, Imm128 - System call.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
StringRef str()
Return a StringRef for the vector contents.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This class wraps the llvm.memcpy intrinsic.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
CallInst * CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static const size_t kNumberOfAccessSizes
static GlobalVariable * createPrivateNonConstGlobalForString(Module &M, StringRef Str)
Create a non-const global initialized with the given string.
static cl::opt< bool > ClKeepGoing("msan-keep-going", cl::desc("keep going after reporting a UMR"), cl::Hidden, cl::init(false))
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getVectorNumElements() const
Class to represent vector types.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
const Value * getFalseValue() const
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
static cl::opt< uint64_t > ClAndMask("msan-and-mask", cl::desc("Define custom MSan AndMask"), cl::Hidden, cl::init(0))
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
void removeAttributes(unsigned i, const AttrBuilder &Attrs)
removes the attributes from the list of attributes.
Predicate getPredicate() const
Return the predicate for this instruction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
unsigned getNumArgOperands() const
static cl::opt< bool > ClEnableKmsan("msan-kernel", cl::desc("Enable KernelMemorySanitizer instrumentation"), cl::Hidden, cl::init(false))
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
static cl::opt< bool > ClHandleICmpExact("msan-handle-icmp-exact", cl::desc("exact handling of relational integer ICmp"), cl::Hidden, cl::init(false))
unsigned getAlignment() const
Return the alignment of the access that is being performed.
LLVM_NODISCARD bool empty() const
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
bool onlyReadsMemory(unsigned OpNo) const
static const MemoryMapParams Linux_X86_64_MemoryMapParams
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static cl::opt< bool > ClHandleLifetimeIntrinsics("msan-handle-lifetime-intrinsics", cl::desc("when possible, poison scoped variables at the beginning of the scope " "(slower, but more precise)"), cl::Hidden, cl::init(true))
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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...
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static const PlatformMemoryMapParams NetBSD_X86_MemoryMapParams
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
static cl::opt< bool > ClCheckConstantShadow("msan-check-constant-shadow", cl::desc("Insert checks for constant shadow values"), cl::Hidden, cl::init(false))
bool isInvoke() const
Return true if a InvokeInst is enclosed.
static const MemoryMapParams Linux_MIPS64_MemoryMapParams
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
static const unsigned kOriginSize
const std::string to_string(const T &Value)
static const MemoryMapParams FreeBSD_I386_MemoryMapParams
bool isCallBr() const
Return true if a CallBrInst is enclosed.
Analysis pass providing the TargetLibraryInfo.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
iterator_range< df_iterator< T > > depth_first(const T &G)
bool isCall() const
Return true if a CallInst is enclosed.
This represents the llvm.va_copy intrinsic.
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static cl::opt< int > ClInstrumentationWithCallThreshold("msan-instrumentation-with-call-threshold", cl::desc("If the function being instrumented requires more than " "this number of checks and origin stores, use callbacks instead of " "inline checks (-1 means never use callbacks)."), cl::Hidden, cl::init(3500))
void setSuccessOrdering(AtomicOrdering Ordering)
Sets the success ordering constraint of this cmpxchg instruction.
ArrayRef< unsigned > getIndices() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
AttributeSet getFnAttributes() const
The function attributes are returned.
BasicBlock::iterator GetInsertPoint() const
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
static cl::opt< bool > ClPoisonUndef("msan-poison-undef", cl::desc("poison undef temps"), cl::Hidden, cl::init(true))
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
StringRef - Represent a constant reference to a string, i.e.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
FunctionPass * createMemorySanitizerLegacyPassPass(MemorySanitizerOptions Options={})
static const PlatformMemoryMapParams FreeBSD_X86_MemoryMapParams
A container for analyses that lazily runs them and caches their results.
Type * getArrayElementType() const
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Value * getPointerOperand()
static IntegerType * getInt8Ty(LLVMContext &C)
static const char *const kMsanModuleCtorName
static Constant * get(ArrayRef< Constant *> V)
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
iterator_range< arg_iterator > args()
static ConstraintInfoVector ParseConstraints(StringRef ConstraintString)
ParseConstraints - Split up the constraint string into the specific constraints and their prefixes...
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.