Skip to content

Commit 9a67c6b

Browse files
committed
[NFC] [HWASan] simplify code
Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D156382
1 parent 27dab4d commit 9a67c6b

File tree

1 file changed

+27
-50
lines changed

1 file changed

+27
-50
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -957,35 +957,22 @@ bool HWAddressSanitizer::ignoreMemIntrinsic(MemIntrinsic *MI) {
957957
void HWAddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) {
958958
IRBuilder<> IRB(MI);
959959
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);
974968
} 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);
989976
}
990977
MI->eraseFromParent();
991978
}
@@ -1005,34 +992,24 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
1005992
*O.Alignment >= O.TypeStoreSize / 8)) {
1006993
size_t AccessSizeIndex = TypeSizeToSizeIndex(O.TypeStoreSize);
1007994
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);
10161000
} else if (OutlinedChecks) {
10171001
instrumentMemAccessOutline(Addr, O.IsWrite, AccessSizeIndex, O.getInsn());
10181002
} else {
10191003
instrumentMemAccessInline(Addr, O.IsWrite, AccessSizeIndex, O.getInsn());
10201004
}
10211005
} 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);
10361013
}
10371014
untagPointerOperand(O.getInsn(), Addr);
10381015

0 commit comments

Comments
 (0)