Skip to content

Commit

Permalink
[NFC] [MTE] [HWASan] Remove unnecessary member of AllocaInfo
Browse files Browse the repository at this point in the history
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D119981
  • Loading branch information
fmayer committed Feb 16, 2022
1 parent 7470244 commit c195add
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 1 addition & 3 deletions llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
Expand Up @@ -19,7 +19,6 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"

namespace llvm {
namespace memtag {
Expand Down Expand Up @@ -75,7 +74,6 @@ Instruction *getUntagLocationIfFunctionExit(Instruction &Inst);

struct AllocaInfo {
AllocaInst *AI;
TrackingVH<Instruction> OldAI; // Track through RAUW to replace debug uses.
SmallVector<IntrinsicInst *, 2> LifetimeStart;
SmallVector<IntrinsicInst *, 2> LifetimeEnd;
SmallVector<DbgVariableIntrinsic *, 2> DbgVariableIntrinsics;
Expand All @@ -102,7 +100,7 @@ class StackInfoBuilder {
};

uint64_t getAllocaSizeInBytes(const AllocaInst &AI);
bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align);
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align);

} // namespace memtag
} // namespace llvm
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AArch64/AArch64StackTagging.cpp
Expand Up @@ -48,6 +48,7 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/IntrinsicsAArch64.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
Expand Down Expand Up @@ -532,9 +533,8 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
for (auto &I : SInfo.AllocasToInstrument) {
memtag::AllocaInfo &Info = I.second;
assert(Info.AI && isInterestingAlloca(*Info.AI));
auto *PrevAI = Info.AI;
if (memtag::alignAndPadAlloca(Info, kTagGranuleSize))
PrevAI->eraseFromParent();
TrackingVH<Instruction> OldAI = Info.AI;
memtag::alignAndPadAlloca(Info, kTagGranuleSize);
AllocaInst *AI = Info.AI;
int Tag = NextTag;
NextTag = (NextTag + 1) % 16;
Expand Down Expand Up @@ -590,7 +590,7 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {

// Fixup debug intrinsics to point to the new alloca.
for (auto DVI : Info.DbgVariableIntrinsics)
DVI->replaceVariableLocationOp(Info.OldAI, Info.AI);
DVI->replaceVariableLocationOp(OldAI, Info.AI);
}

// If we have instrumented at least one alloca, all unrecognized lifetime
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Expand Up @@ -1378,8 +1378,7 @@ bool HWAddressSanitizer::instrumentStack(
II->eraseFromParent();
}
}
if (memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment())))
AI->eraseFromParent();
memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment()));
}
for (auto &I : SInfo.UnrecognizedLifetimes)
I->eraseFromParent();
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
Expand Up @@ -67,7 +67,6 @@ void StackInfoBuilder::visit(Instruction &Inst) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) {
if (IsInterestingAlloca(*AI)) {
Info.AllocasToInstrument[AI].AI = AI;
Info.AllocasToInstrument[AI].OldAI = AI;
}
return;
}
Expand Down Expand Up @@ -109,15 +108,15 @@ uint64_t getAllocaSizeInBytes(const AllocaInst &AI) {
return AI.getAllocationSizeInBits(DL).getValue() / 8;
}

bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) {
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) {
const Align NewAlignment = max(MaybeAlign(Info.AI->getAlign()), Alignment);
Info.AI->setAlignment(NewAlignment);
auto &Ctx = Info.AI->getFunction()->getContext();

uint64_t Size = getAllocaSizeInBytes(*Info.AI);
uint64_t AlignedSize = alignTo(Size, Alignment);
if (Size == AlignedSize)
return false;
return;

// Add padding to the alloca.
Type *AllocatedType =
Expand All @@ -139,8 +138,8 @@ bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) {

auto *NewPtr = new BitCastInst(NewAI, Info.AI->getType(), "", Info.AI);
Info.AI->replaceAllUsesWith(NewPtr);
Info.AI->eraseFromParent();
Info.AI = NewAI;
return true;
}

} // namespace memtag
Expand Down

0 comments on commit c195add

Please sign in to comment.