@@ -574,7 +574,7 @@ class MemorySanitizer {
574
574
575
575
Triple TargetTriple;
576
576
LLVMContext *C;
577
- Type *IntptrTy;
577
+ Type *IntptrTy; // /< Integer type with the size of a ptr in default AS.
578
578
Type *OriginTy;
579
579
580
580
// XxxTLS variables represent the per-thread state in MSan and per-task state
@@ -1676,7 +1676,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1676
1676
VectTy->getElementCount ());
1677
1677
}
1678
1678
assert (IntPtrTy == MS.IntptrTy );
1679
- return ShadowTy-> getPointerTo ( );
1679
+ return PointerType::get (*MS. C , 0 );
1680
1680
}
1681
1681
1682
1682
Constant *constToIntPtr (Type *IntPtrTy, uint64_t C) const {
@@ -1800,11 +1800,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1800
1800
// TODO: Support callbacs with vectors of addresses.
1801
1801
unsigned NumElements = cast<FixedVectorType>(VectTy)->getNumElements ();
1802
1802
Value *ShadowPtrs = ConstantInt::getNullValue (
1803
- FixedVectorType::get (ShadowTy-> getPointerTo (), NumElements));
1803
+ FixedVectorType::get (IRB. getPtrTy (), NumElements));
1804
1804
Value *OriginPtrs = nullptr ;
1805
1805
if (MS.TrackOrigins )
1806
1806
OriginPtrs = ConstantInt::getNullValue (
1807
- FixedVectorType::get (MS. OriginTy -> getPointerTo (), NumElements));
1807
+ FixedVectorType::get (IRB. getPtrTy (), NumElements));
1808
1808
for (unsigned i = 0 ; i < NumElements; ++i) {
1809
1809
Value *OneAddr =
1810
1810
IRB.CreateExtractElement (Addr, ConstantInt::get (IRB.getInt32Ty (), i));
@@ -1832,33 +1832,30 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1832
1832
// / Compute the shadow address for a given function argument.
1833
1833
// /
1834
1834
// / Shadow = ParamTLS+ArgOffset.
1835
- Value *getShadowPtrForArgument (Value *A, IRBuilder<> &IRB, int ArgOffset) {
1835
+ Value *getShadowPtrForArgument (IRBuilder<> &IRB, int ArgOffset) {
1836
1836
Value *Base = IRB.CreatePointerCast (MS.ParamTLS , MS.IntptrTy );
1837
1837
if (ArgOffset)
1838
1838
Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
1839
- return IRB.CreateIntToPtr (Base, PointerType::get (getShadowTy (A), 0 ),
1840
- " _msarg" );
1839
+ return IRB.CreateIntToPtr (Base, IRB.getPtrTy (0 ), " _msarg" );
1841
1840
}
1842
1841
1843
1842
// / Compute the origin address for a given function argument.
1844
- Value *getOriginPtrForArgument (Value *A, IRBuilder<> &IRB, int ArgOffset) {
1843
+ Value *getOriginPtrForArgument (IRBuilder<> &IRB, int ArgOffset) {
1845
1844
if (!MS.TrackOrigins )
1846
1845
return nullptr ;
1847
1846
Value *Base = IRB.CreatePointerCast (MS.ParamOriginTLS , MS.IntptrTy );
1848
1847
if (ArgOffset)
1849
1848
Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
1850
- return IRB.CreateIntToPtr (Base, PointerType::get (MS.OriginTy , 0 ),
1851
- " _msarg_o" );
1849
+ return IRB.CreateIntToPtr (Base, IRB.getPtrTy (0 ), " _msarg_o" );
1852
1850
}
1853
1851
1854
1852
// / Compute the shadow address for a retval.
1855
- Value *getShadowPtrForRetval (Value *A, IRBuilder<> &IRB) {
1856
- return IRB.CreatePointerCast (MS.RetvalTLS ,
1857
- PointerType::get (getShadowTy (A), 0 ), " _msret" );
1853
+ Value *getShadowPtrForRetval (IRBuilder<> &IRB) {
1854
+ return IRB.CreatePointerCast (MS.RetvalTLS , IRB.getPtrTy (0 ), " _msret" );
1858
1855
}
1859
1856
1860
1857
// / Compute the origin address for a retval.
1861
- Value *getOriginPtrForRetval (IRBuilder<> &IRB ) {
1858
+ Value *getOriginPtrForRetval () {
1862
1859
// We keep a single origin for the entire retval. Might be too optimistic.
1863
1860
return MS.RetvalOriginTLS ;
1864
1861
}
@@ -1982,7 +1979,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1982
1979
CpShadowPtr, Constant::getNullValue (EntryIRB.getInt8Ty ()),
1983
1980
Size, ArgAlign);
1984
1981
} else {
1985
- Value *Base = getShadowPtrForArgument (&FArg, EntryIRB, ArgOffset);
1982
+ Value *Base = getShadowPtrForArgument (EntryIRB, ArgOffset);
1986
1983
const Align CopyAlign = std::min (ArgAlign, kShadowTLSAlignment );
1987
1984
Value *Cpy = EntryIRB.CreateMemCpy (CpShadowPtr, CopyAlign, Base,
1988
1985
CopyAlign, Size);
@@ -1991,7 +1988,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1991
1988
1992
1989
if (MS.TrackOrigins ) {
1993
1990
Value *OriginPtr =
1994
- getOriginPtrForArgument (&FArg, EntryIRB, ArgOffset);
1991
+ getOriginPtrForArgument (EntryIRB, ArgOffset);
1995
1992
// FIXME: OriginSize should be:
1996
1993
// alignTo(V % kMinOriginAlignment + Size, kMinOriginAlignment)
1997
1994
unsigned OriginSize = alignTo (Size, kMinOriginAlignment );
@@ -2010,12 +2007,12 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
2010
2007
setOrigin (A, getCleanOrigin ());
2011
2008
} else {
2012
2009
// Shadow over TLS
2013
- Value *Base = getShadowPtrForArgument (&FArg, EntryIRB, ArgOffset);
2010
+ Value *Base = getShadowPtrForArgument (EntryIRB, ArgOffset);
2014
2011
ShadowPtr = EntryIRB.CreateAlignedLoad (getShadowTy (&FArg), Base,
2015
2012
kShadowTLSAlignment );
2016
2013
if (MS.TrackOrigins ) {
2017
2014
Value *OriginPtr =
2018
- getOriginPtrForArgument (&FArg, EntryIRB, ArgOffset);
2015
+ getOriginPtrForArgument (EntryIRB, ArgOffset);
2019
2016
setOrigin (A, EntryIRB.CreateLoad (MS.OriginTy , OriginPtr));
2020
2017
}
2021
2018
}
@@ -3382,11 +3379,12 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
3382
3379
IRBuilder<> IRB (&I);
3383
3380
Value *Addr = I.getArgOperand (0 );
3384
3381
Type *Ty = IRB.getInt32Ty ();
3382
+ Type *PtrTy = IRB.getPtrTy ();
3385
3383
Value *ShadowPtr =
3386
3384
getShadowOriginPtr (Addr, IRB, Ty, Align (1 ), /* isStore*/ true ).first ;
3387
3385
3388
3386
IRB.CreateStore (getCleanShadow (Ty),
3389
- IRB.CreatePointerCast (ShadowPtr, Ty-> getPointerTo () ));
3387
+ IRB.CreatePointerCast (ShadowPtr, PtrTy ));
3390
3388
3391
3389
if (ClCheckAccessAddress)
3392
3390
insertShadowCheck (Addr, &I);
@@ -4188,7 +4186,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4188
4186
// in that case getShadow() will copy the actual arg shadow to
4189
4187
// __msan_param_tls.
4190
4188
Value *ArgShadow = getShadow (A);
4191
- Value *ArgShadowBase = getShadowPtrForArgument (A, IRB, ArgOffset);
4189
+ Value *ArgShadowBase = getShadowPtrForArgument (IRB, ArgOffset);
4192
4190
LLVM_DEBUG (dbgs () << " Arg#" << i << " : " << *A
4193
4191
<< " Shadow: " << *ArgShadow << " \n " );
4194
4192
if (ByVal) {
@@ -4215,7 +4213,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4215
4213
Store = IRB.CreateMemCpy (ArgShadowBase, Alignment, AShadowPtr,
4216
4214
Alignment, Size);
4217
4215
if (MS.TrackOrigins ) {
4218
- Value *ArgOriginBase = getOriginPtrForArgument (A, IRB, ArgOffset);
4216
+ Value *ArgOriginBase = getOriginPtrForArgument (IRB, ArgOffset);
4219
4217
// FIXME: OriginSize should be:
4220
4218
// alignTo(A % kMinOriginAlignment + Size, kMinOriginAlignment)
4221
4219
unsigned OriginSize = alignTo (Size, kMinOriginAlignment );
@@ -4237,7 +4235,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4237
4235
Constant *Cst = dyn_cast<Constant>(ArgShadow);
4238
4236
if (MS.TrackOrigins && !(Cst && Cst->isNullValue ())) {
4239
4237
IRB.CreateStore (getOrigin (A),
4240
- getOriginPtrForArgument (A, IRB, ArgOffset));
4238
+ getOriginPtrForArgument (IRB, ArgOffset));
4241
4239
}
4242
4240
}
4243
4241
(void )Store;
@@ -4269,7 +4267,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4269
4267
4270
4268
IRBuilder<> IRBBefore (&CB);
4271
4269
// Until we have full dynamic coverage, make sure the retval shadow is 0.
4272
- Value *Base = getShadowPtrForRetval (&CB, IRBBefore);
4270
+ Value *Base = getShadowPtrForRetval (IRBBefore);
4273
4271
IRBBefore.CreateAlignedStore (getCleanShadow (&CB), Base,
4274
4272
kShadowTLSAlignment );
4275
4273
BasicBlock::iterator NextInsn;
@@ -4294,12 +4292,12 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4294
4292
}
4295
4293
IRBuilder<> IRBAfter (&*NextInsn);
4296
4294
Value *RetvalShadow = IRBAfter.CreateAlignedLoad (
4297
- getShadowTy (&CB), getShadowPtrForRetval (&CB, IRBAfter),
4295
+ getShadowTy (&CB), getShadowPtrForRetval (IRBAfter),
4298
4296
kShadowTLSAlignment , " _msret" );
4299
4297
setShadow (&CB, RetvalShadow);
4300
4298
if (MS.TrackOrigins )
4301
4299
setOrigin (&CB, IRBAfter.CreateLoad (MS.OriginTy ,
4302
- getOriginPtrForRetval (IRBAfter )));
4300
+ getOriginPtrForRetval ()));
4303
4301
}
4304
4302
4305
4303
bool isAMustTailRetVal (Value *RetVal) {
@@ -4320,7 +4318,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4320
4318
// Don't emit the epilogue for musttail call returns.
4321
4319
if (isAMustTailRetVal (RetVal))
4322
4320
return ;
4323
- Value *ShadowPtr = getShadowPtrForRetval (RetVal, IRB);
4321
+ Value *ShadowPtr = getShadowPtrForRetval (IRB);
4324
4322
bool HasNoUndef = F.hasRetAttribute (Attribute::NoUndef);
4325
4323
bool StoreShadow = !(MS.EagerChecks && HasNoUndef);
4326
4324
// FIXME: Consider using SpecialCaseList to specify a list of functions that
@@ -4340,7 +4338,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
4340
4338
if (StoreShadow) {
4341
4339
IRB.CreateAlignedStore (Shadow, ShadowPtr, kShadowTLSAlignment );
4342
4340
if (MS.TrackOrigins && StoreOrigin)
4343
- IRB.CreateStore (getOrigin (RetVal), getOriginPtrForRetval (IRB ));
4341
+ IRB.CreateStore (getOrigin (RetVal), getOriginPtrForRetval ());
4344
4342
}
4345
4343
}
4346
4344
0 commit comments