@@ -1923,20 +1923,17 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
1923
1923
// /
1924
1924
// / Shadow = ParamTLS+ArgOffset.
1925
1925
Value *getShadowPtrForArgument (IRBuilder<> &IRB, int ArgOffset) {
1926
- Value *Base = IRB.CreatePointerCast (MS.ParamTLS , MS.IntptrTy );
1927
- if (ArgOffset)
1928
- Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
1929
- return IRB.CreateIntToPtr (Base, IRB.getPtrTy (0 ), " _msarg" );
1926
+ return IRB.CreatePtrAdd (MS.ParamTLS ,
1927
+ ConstantInt::get (MS.IntptrTy , ArgOffset), " _msarg" );
1930
1928
}
1931
1929
1932
1930
// / Compute the origin address for a given function argument.
1933
1931
Value *getOriginPtrForArgument (IRBuilder<> &IRB, int ArgOffset) {
1934
1932
if (!MS.TrackOrigins )
1935
1933
return nullptr ;
1936
- Value *Base = IRB.CreatePointerCast (MS.ParamOriginTLS , MS.IntptrTy );
1937
- if (ArgOffset)
1938
- Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
1939
- return IRB.CreateIntToPtr (Base, IRB.getPtrTy (0 ), " _msarg_o" );
1934
+ return IRB.CreatePtrAdd (MS.ParamOriginTLS ,
1935
+ ConstantInt::get (MS.IntptrTy , ArgOffset),
1936
+ " _msarg_o" );
1940
1937
}
1941
1938
1942
1939
// / Compute the shadow address for a retval.
@@ -7219,9 +7216,8 @@ struct VarArgHelperBase : public VarArgHelper {
7219
7216
7220
7217
// / Compute the shadow address for a given va_arg.
7221
7218
Value *getShadowPtrForVAArgument (IRBuilder<> &IRB, unsigned ArgOffset) {
7222
- Value *Base = IRB.CreatePointerCast (MS.VAArgTLS , MS.IntptrTy );
7223
- Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
7224
- return IRB.CreateIntToPtr (Base, MS.PtrTy , " _msarg_va_s" );
7219
+ return IRB.CreatePtrAdd (
7220
+ MS.VAArgTLS , ConstantInt::get (MS.IntptrTy , ArgOffset), " _msarg_va_s" );
7225
7221
}
7226
7222
7227
7223
// / Compute the shadow address for a given va_arg.
@@ -7235,12 +7231,12 @@ struct VarArgHelperBase : public VarArgHelper {
7235
7231
7236
7232
// / Compute the origin address for a given va_arg.
7237
7233
Value *getOriginPtrForVAArgument (IRBuilder<> &IRB, int ArgOffset) {
7238
- Value *Base = IRB.CreatePointerCast (MS.VAArgOriginTLS , MS.IntptrTy );
7239
7234
// getOriginPtrForVAArgument() is always called after
7240
7235
// getShadowPtrForVAArgument(), so __msan_va_arg_origin_tls can never
7241
7236
// overflow.
7242
- Base = IRB.CreateAdd (Base, ConstantInt::get (MS.IntptrTy , ArgOffset));
7243
- return IRB.CreateIntToPtr (Base, MS.PtrTy , " _msarg_va_o" );
7237
+ return IRB.CreatePtrAdd (MS.VAArgOriginTLS ,
7238
+ ConstantInt::get (MS.IntptrTy , ArgOffset),
7239
+ " _msarg_va_o" );
7244
7240
}
7245
7241
7246
7242
void CleanUnusedTLS (IRBuilder<> &IRB, Value *ShadowBase,
@@ -7467,10 +7463,8 @@ struct VarArgAMD64Helper : public VarArgHelperBase {
7467
7463
NextNodeIRBuilder IRB (OrigInst);
7468
7464
Value *VAListTag = OrigInst->getArgOperand (0 );
7469
7465
7470
- Value *RegSaveAreaPtrPtr = IRB.CreateIntToPtr (
7471
- IRB.CreateAdd (IRB.CreatePtrToInt (VAListTag, MS.IntptrTy ),
7472
- ConstantInt::get (MS.IntptrTy , 16 )),
7473
- MS.PtrTy );
7466
+ Value *RegSaveAreaPtrPtr =
7467
+ IRB.CreatePtrAdd (VAListTag, ConstantInt::get (MS.IntptrTy , 16 ));
7474
7468
Value *RegSaveAreaPtr = IRB.CreateLoad (MS.PtrTy , RegSaveAreaPtrPtr);
7475
7469
Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
7476
7470
const Align Alignment = Align (16 );
@@ -7482,10 +7476,8 @@ struct VarArgAMD64Helper : public VarArgHelperBase {
7482
7476
if (MS.TrackOrigins )
7483
7477
IRB.CreateMemCpy (RegSaveAreaOriginPtr, Alignment, VAArgTLSOriginCopy,
7484
7478
Alignment, AMD64FpEndOffset);
7485
- Value *OverflowArgAreaPtrPtr = IRB.CreateIntToPtr (
7486
- IRB.CreateAdd (IRB.CreatePtrToInt (VAListTag, MS.IntptrTy ),
7487
- ConstantInt::get (MS.IntptrTy , 8 )),
7488
- MS.PtrTy );
7479
+ Value *OverflowArgAreaPtrPtr =
7480
+ IRB.CreatePtrAdd (VAListTag, ConstantInt::get (MS.IntptrTy , 8 ));
7489
7481
Value *OverflowArgAreaPtr =
7490
7482
IRB.CreateLoad (MS.PtrTy , OverflowArgAreaPtrPtr);
7491
7483
Value *OverflowArgAreaShadowPtr, *OverflowArgAreaOriginPtr;
@@ -7615,19 +7607,15 @@ struct VarArgAArch64Helper : public VarArgHelperBase {
7615
7607
7616
7608
// Retrieve a va_list field of 'void*' size.
7617
7609
Value *getVAField64 (IRBuilder<> &IRB, Value *VAListTag, int offset) {
7618
- Value *SaveAreaPtrPtr = IRB.CreateIntToPtr (
7619
- IRB.CreateAdd (IRB.CreatePtrToInt (VAListTag, MS.IntptrTy ),
7620
- ConstantInt::get (MS.IntptrTy , offset)),
7621
- MS.PtrTy );
7610
+ Value *SaveAreaPtrPtr =
7611
+ IRB.CreatePtrAdd (VAListTag, ConstantInt::get (MS.IntptrTy , offset));
7622
7612
return IRB.CreateLoad (Type::getInt64Ty (*MS.C ), SaveAreaPtrPtr);
7623
7613
}
7624
7614
7625
7615
// Retrieve a va_list field of 'int' size.
7626
7616
Value *getVAField32 (IRBuilder<> &IRB, Value *VAListTag, int offset) {
7627
- Value *SaveAreaPtr = IRB.CreateIntToPtr (
7628
- IRB.CreateAdd (IRB.CreatePtrToInt (VAListTag, MS.IntptrTy ),
7629
- ConstantInt::get (MS.IntptrTy , offset)),
7630
- MS.PtrTy );
7617
+ Value *SaveAreaPtr =
7618
+ IRB.CreatePtrAdd (VAListTag, ConstantInt::get (MS.IntptrTy , offset));
7631
7619
Value *SaveArea32 = IRB.CreateLoad (IRB.getInt32Ty (), SaveAreaPtr);
7632
7620
return IRB.CreateSExt (SaveArea32, MS.IntptrTy );
7633
7621
}
0 commit comments