Skip to content

Commit 45b6a33

Browse files
committed
[ASAN] Use TypeSize in InterestingMemoryOperand [mostly NFC]
This is a mechanical prep change for scalable vector support. All it does is move the point of TypeSize to unsigned (i.e. the unsafe cast) closer to point of use.
1 parent c546f13 commit 45b6a33

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class InterestingMemoryOperand {
2727
Use *PtrUse;
2828
bool IsWrite;
2929
Type *OpType;
30-
uint64_t TypeSize;
30+
TypeSize TypeStoreSize = TypeSize::Fixed(0);
3131
MaybeAlign Alignment;
3232
// The mask Value, if we're looking at a masked load/store.
3333
Value *MaybeMask;
@@ -38,7 +38,7 @@ class InterestingMemoryOperand {
3838
: IsWrite(IsWrite), OpType(OpType), Alignment(Alignment),
3939
MaybeMask(MaybeMask) {
4040
const DataLayout &DL = I->getModule()->getDataLayout();
41-
TypeSize = DL.getTypeStoreSizeInBits(OpType);
41+
TypeStoreSize = DL.getTypeStoreSizeInBits(OpType);
4242
PtrUse = &I->getOperandUse(OperandNo);
4343
}
4444

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ void AddressSanitizer::instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
14921492
// dynamically initialized global is always valid.
14931493
GlobalVariable *G = dyn_cast<GlobalVariable>(getUnderlyingObject(Addr));
14941494
if (G && (!ClInitializers || GlobalIsLinkerInitialized(G)) &&
1495-
isSafeAccess(ObjSizeVis, Addr, O.TypeSize)) {
1495+
isSafeAccess(ObjSizeVis, Addr, O.TypeStoreSize)) {
14961496
NumOptimizedAccessesToGlobalVar++;
14971497
return;
14981498
}
@@ -1501,7 +1501,7 @@ void AddressSanitizer::instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
15011501
if (ClOpt && ClOptStack) {
15021502
// A direct inbounds access to a stack variable is always valid.
15031503
if (isa<AllocaInst>(getUnderlyingObject(Addr)) &&
1504-
isSafeAccess(ObjSizeVis, Addr, O.TypeSize)) {
1504+
isSafeAccess(ObjSizeVis, Addr, O.TypeStoreSize)) {
15051505
NumOptimizedAccessesToStackVar++;
15061506
return;
15071507
}
@@ -1519,7 +1519,7 @@ void AddressSanitizer::instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
15191519
O.IsWrite, nullptr, UseCalls, Exp);
15201520
} else {
15211521
doInstrumentAddress(this, O.getInsn(), O.getInsn(), Addr, O.Alignment,
1522-
Granularity, O.TypeSize, O.IsWrite, nullptr, UseCalls,
1522+
Granularity, O.TypeStoreSize, O.IsWrite, nullptr, UseCalls,
15231523
Exp);
15241524
}
15251525
}

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,11 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
967967
return false; // FIXME
968968

969969
IRBuilder<> IRB(O.getInsn());
970-
if (isPowerOf2_64(O.TypeSize) &&
971-
(O.TypeSize / 8 <= (1ULL << (kNumberOfAccessSizes - 1))) &&
970+
if (isPowerOf2_64(O.TypeStoreSize) &&
971+
(O.TypeStoreSize / 8 <= (1ULL << (kNumberOfAccessSizes - 1))) &&
972972
(!O.Alignment || *O.Alignment >= Mapping.getObjectAlignment() ||
973-
*O.Alignment >= O.TypeSize / 8)) {
974-
size_t AccessSizeIndex = TypeSizeToSizeIndex(O.TypeSize);
973+
*O.Alignment >= O.TypeStoreSize / 8)) {
974+
size_t AccessSizeIndex = TypeSizeToSizeIndex(O.TypeStoreSize);
975975
if (InstrumentWithCalls) {
976976
IRB.CreateCall(HwasanMemoryAccessCallback[O.IsWrite][AccessSizeIndex],
977977
IRB.CreatePointerCast(Addr, IntptrTy));
@@ -983,7 +983,7 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
983983
} else {
984984
IRB.CreateCall(HwasanMemoryAccessCallbackSized[O.IsWrite],
985985
{IRB.CreatePointerCast(Addr, IntptrTy),
986-
ConstantInt::get(IntptrTy, O.TypeSize / 8)});
986+
ConstantInt::get(IntptrTy, O.TypeStoreSize / 8)});
987987
}
988988
untagPointerOperand(O.getInsn(), Addr);
989989

0 commit comments

Comments
 (0)