@@ -957,35 +957,22 @@ bool HWAddressSanitizer::ignoreMemIntrinsic(MemIntrinsic *MI) {
957
957
void HWAddressSanitizer::instrumentMemIntrinsic (MemIntrinsic *MI) {
958
958
IRBuilder<> IRB (MI);
959
959
if (isa<MemTransferInst>(MI)) {
960
- if (UseMatchAllCallback) {
961
- IRB.CreateCall (
962
- isa<MemMoveInst>(MI) ? HwasanMemmove : HwasanMemcpy,
963
- {IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
964
- IRB.CreatePointerCast (MI->getOperand (1 ), IRB.getInt8PtrTy ()),
965
- IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false ),
966
- ConstantInt::get (Int8Ty, *MatchAllTag)});
967
- } else {
968
- IRB.CreateCall (
969
- isa<MemMoveInst>(MI) ? HwasanMemmove : HwasanMemcpy,
970
- {IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
971
- IRB.CreatePointerCast (MI->getOperand (1 ), IRB.getInt8PtrTy ()),
972
- IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )});
973
- }
960
+ SmallVector<Value *, 4 > Args{
961
+ IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
962
+ IRB.CreatePointerCast (MI->getOperand (1 ), IRB.getInt8PtrTy ()),
963
+ IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )};
964
+
965
+ if (UseMatchAllCallback)
966
+ Args.emplace_back (ConstantInt::get (Int8Ty, *MatchAllTag));
967
+ IRB.CreateCall (isa<MemMoveInst>(MI) ? HwasanMemmove : HwasanMemcpy, Args);
974
968
} else if (isa<MemSetInst>(MI)) {
975
- if (UseMatchAllCallback) {
976
- IRB.CreateCall (
977
- HwasanMemset,
978
- {IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
979
- IRB.CreateIntCast (MI->getOperand (1 ), IRB.getInt32Ty (), false ),
980
- IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false ),
981
- ConstantInt::get (Int8Ty, *MatchAllTag)});
982
- } else {
983
- IRB.CreateCall (
984
- HwasanMemset,
985
- {IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
986
- IRB.CreateIntCast (MI->getOperand (1 ), IRB.getInt32Ty (), false ),
987
- IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )});
988
- }
969
+ SmallVector<Value *, 4 > Args{
970
+ IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
971
+ IRB.CreateIntCast (MI->getOperand (1 ), IRB.getInt32Ty (), false ),
972
+ IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )};
973
+ if (UseMatchAllCallback)
974
+ Args.emplace_back (ConstantInt::get (Int8Ty, *MatchAllTag));
975
+ IRB.CreateCall (HwasanMemset, Args);
989
976
}
990
977
MI->eraseFromParent ();
991
978
}
@@ -1005,34 +992,24 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
1005
992
*O.Alignment >= O.TypeStoreSize / 8 )) {
1006
993
size_t AccessSizeIndex = TypeSizeToSizeIndex (O.TypeStoreSize );
1007
994
if (InstrumentWithCalls) {
1008
- if (UseMatchAllCallback) {
1009
- IRB.CreateCall (HwasanMemoryAccessCallback[O.IsWrite ][AccessSizeIndex],
1010
- {IRB.CreatePointerCast (Addr, IntptrTy),
1011
- ConstantInt::get (Int8Ty, *MatchAllTag)});
1012
- } else {
1013
- IRB.CreateCall (HwasanMemoryAccessCallback[O.IsWrite ][AccessSizeIndex],
1014
- IRB.CreatePointerCast (Addr, IntptrTy));
1015
- }
995
+ SmallVector<Value *, 2 > Args{IRB.CreatePointerCast (Addr, IntptrTy)};
996
+ if (UseMatchAllCallback)
997
+ Args.emplace_back (ConstantInt::get (Int8Ty, *MatchAllTag));
998
+ IRB.CreateCall (HwasanMemoryAccessCallback[O.IsWrite ][AccessSizeIndex],
999
+ Args);
1016
1000
} else if (OutlinedChecks) {
1017
1001
instrumentMemAccessOutline (Addr, O.IsWrite , AccessSizeIndex, O.getInsn ());
1018
1002
} else {
1019
1003
instrumentMemAccessInline (Addr, O.IsWrite , AccessSizeIndex, O.getInsn ());
1020
1004
}
1021
1005
} else {
1022
- if (UseMatchAllCallback) {
1023
- IRB.CreateCall (
1024
- HwasanMemoryAccessCallbackSized[O.IsWrite ],
1025
- {IRB.CreatePointerCast (Addr, IntptrTy),
1026
- IRB.CreateUDiv (IRB.CreateTypeSize (IntptrTy, O.TypeStoreSize ),
1027
- ConstantInt::get (IntptrTy, 8 )),
1028
- ConstantInt::get (Int8Ty, *MatchAllTag)});
1029
- } else {
1030
- IRB.CreateCall (
1031
- HwasanMemoryAccessCallbackSized[O.IsWrite ],
1032
- {IRB.CreatePointerCast (Addr, IntptrTy),
1033
- IRB.CreateUDiv (IRB.CreateTypeSize (IntptrTy, O.TypeStoreSize ),
1034
- ConstantInt::get (IntptrTy, 8 ))});
1035
- }
1006
+ SmallVector<Value *, 3 > Args{
1007
+ IRB.CreatePointerCast (Addr, IntptrTy),
1008
+ IRB.CreateUDiv (IRB.CreateTypeSize (IntptrTy, O.TypeStoreSize ),
1009
+ ConstantInt::get (IntptrTy, 8 ))};
1010
+ if (UseMatchAllCallback)
1011
+ Args.emplace_back (ConstantInt::get (Int8Ty, *MatchAllTag));
1012
+ IRB.CreateCall (HwasanMemoryAccessCallbackSized[O.IsWrite ], Args);
1036
1013
}
1037
1014
untagPointerOperand (O.getInsn (), Addr);
1038
1015
0 commit comments