|
33 | 33 | #include "llvm/IR/Function.h"
|
34 | 34 | #include "llvm/IR/IRBuilder.h"
|
35 | 35 | #include "llvm/IR/InlineAsm.h"
|
| 36 | +#include "llvm/IR/InstIterator.h" |
36 | 37 | #include "llvm/IR/InstVisitor.h"
|
37 | 38 | #include "llvm/IR/Instruction.h"
|
38 | 39 | #include "llvm/IR/Instructions.h"
|
@@ -1480,59 +1481,56 @@ bool HWAddressSanitizer::sanitizeFunction(
|
1480 | 1481 | SmallVector<Instruction *, 4> UnrecognizedLifetimes;
|
1481 | 1482 | DenseMap<AllocaInst *, std::vector<DbgVariableIntrinsic *>> AllocaDbgMap;
|
1482 | 1483 | bool CallsReturnTwice = false;
|
1483 |
| - for (auto &BB : F) { |
1484 |
| - for (auto &Inst : BB) { |
1485 |
| - if (CallInst *CI = dyn_cast<CallInst>(&Inst)) { |
1486 |
| - if (CI->canReturnTwice()) { |
1487 |
| - CallsReturnTwice = true; |
1488 |
| - } |
| 1484 | + for (auto &Inst : instructions(F)) { |
| 1485 | + if (CallInst *CI = dyn_cast<CallInst>(&Inst)) { |
| 1486 | + if (CI->canReturnTwice()) { |
| 1487 | + CallsReturnTwice = true; |
| 1488 | + } |
| 1489 | + } |
| 1490 | + if (InstrumentStack) { |
| 1491 | + if (AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) { |
| 1492 | + if (isInterestingAlloca(*AI)) |
| 1493 | + AllocasToInstrument.insert({AI, {}}); |
| 1494 | + continue; |
1489 | 1495 | }
|
1490 |
| - if (InstrumentStack) { |
1491 |
| - if (AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) { |
1492 |
| - if (isInterestingAlloca(*AI)) |
1493 |
| - AllocasToInstrument.insert({AI, {}}); |
| 1496 | + auto *II = dyn_cast<IntrinsicInst>(&Inst); |
| 1497 | + if (II && (II->getIntrinsicID() == Intrinsic::lifetime_start || |
| 1498 | + II->getIntrinsicID() == Intrinsic::lifetime_end)) { |
| 1499 | + AllocaInst *AI = findAllocaForValue(II->getArgOperand(1)); |
| 1500 | + if (!AI) { |
| 1501 | + UnrecognizedLifetimes.push_back(&Inst); |
1494 | 1502 | continue;
|
1495 | 1503 | }
|
1496 |
| - auto *II = dyn_cast<IntrinsicInst>(&Inst); |
1497 |
| - if (II && (II->getIntrinsicID() == Intrinsic::lifetime_start || |
1498 |
| - II->getIntrinsicID() == Intrinsic::lifetime_end)) { |
1499 |
| - AllocaInst *AI = findAllocaForValue(II->getArgOperand(1)); |
1500 |
| - if (!AI) { |
1501 |
| - UnrecognizedLifetimes.push_back(&Inst); |
1502 |
| - continue; |
1503 |
| - } |
1504 |
| - if (!isInterestingAlloca(*AI)) |
1505 |
| - continue; |
1506 |
| - if (II->getIntrinsicID() == Intrinsic::lifetime_start) |
1507 |
| - AllocasToInstrument[AI].LifetimeStart.push_back(II); |
1508 |
| - else |
1509 |
| - AllocasToInstrument[AI].LifetimeEnd.push_back(II); |
| 1504 | + if (!isInterestingAlloca(*AI)) |
1510 | 1505 | continue;
|
1511 |
| - } |
| 1506 | + if (II->getIntrinsicID() == Intrinsic::lifetime_start) |
| 1507 | + AllocasToInstrument[AI].LifetimeStart.push_back(II); |
| 1508 | + else |
| 1509 | + AllocasToInstrument[AI].LifetimeEnd.push_back(II); |
| 1510 | + continue; |
1512 | 1511 | }
|
| 1512 | + } |
1513 | 1513 |
|
1514 |
| - Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst); |
1515 |
| - if (ExitUntag) |
1516 |
| - RetVec.push_back(ExitUntag); |
| 1514 | + Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst); |
| 1515 | + if (ExitUntag) |
| 1516 | + RetVec.push_back(ExitUntag); |
1517 | 1517 |
|
1518 |
| - if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) { |
1519 |
| - for (Value *V : DVI->location_ops()) { |
1520 |
| - if (auto *Alloca = dyn_cast_or_null<AllocaInst>(V)) |
1521 |
| - if (!AllocaDbgMap.count(Alloca) || |
1522 |
| - AllocaDbgMap[Alloca].back() != DVI) |
1523 |
| - AllocaDbgMap[Alloca].push_back(DVI); |
1524 |
| - } |
| 1518 | + if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) { |
| 1519 | + for (Value *V : DVI->location_ops()) { |
| 1520 | + if (auto *Alloca = dyn_cast_or_null<AllocaInst>(V)) |
| 1521 | + if (!AllocaDbgMap.count(Alloca) || AllocaDbgMap[Alloca].back() != DVI) |
| 1522 | + AllocaDbgMap[Alloca].push_back(DVI); |
1525 | 1523 | }
|
| 1524 | + } |
1526 | 1525 |
|
1527 |
| - if (InstrumentLandingPads && isa<LandingPadInst>(Inst)) |
1528 |
| - LandingPadVec.push_back(&Inst); |
| 1526 | + if (InstrumentLandingPads && isa<LandingPadInst>(Inst)) |
| 1527 | + LandingPadVec.push_back(&Inst); |
1529 | 1528 |
|
1530 |
| - getInterestingMemoryOperands(&Inst, OperandsToInstrument); |
| 1529 | + getInterestingMemoryOperands(&Inst, OperandsToInstrument); |
1531 | 1530 |
|
1532 |
| - if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(&Inst)) |
1533 |
| - if (!ignoreMemIntrinsic(MI)) |
1534 |
| - IntrinToInstrument.push_back(MI); |
1535 |
| - } |
| 1531 | + if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(&Inst)) |
| 1532 | + if (!ignoreMemIntrinsic(MI)) |
| 1533 | + IntrinToInstrument.push_back(MI); |
1536 | 1534 | }
|
1537 | 1535 |
|
1538 | 1536 | initializeCallbacks(*F.getParent());
|
@@ -1580,16 +1578,14 @@ bool HWAddressSanitizer::sanitizeFunction(
|
1580 | 1578 | padInterestingAllocas(AllocasToInstrument);
|
1581 | 1579 |
|
1582 | 1580 | if (!AllocaToPaddedAllocaMap.empty()) {
|
1583 |
| - for (auto &BB : F) { |
1584 |
| - for (auto &Inst : BB) { |
1585 |
| - if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) { |
1586 |
| - SmallDenseSet<Value *> LocationOps(DVI->location_ops().begin(), |
1587 |
| - DVI->location_ops().end()); |
1588 |
| - for (Value *V : LocationOps) { |
1589 |
| - if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) { |
1590 |
| - if (auto *NewAI = AllocaToPaddedAllocaMap.lookup(AI)) |
1591 |
| - DVI->replaceVariableLocationOp(V, NewAI); |
1592 |
| - } |
| 1581 | + for (auto &Inst : instructions(F)) { |
| 1582 | + if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) { |
| 1583 | + SmallDenseSet<Value *> LocationOps(DVI->location_ops().begin(), |
| 1584 | + DVI->location_ops().end()); |
| 1585 | + for (Value *V : LocationOps) { |
| 1586 | + if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) { |
| 1587 | + if (auto *NewAI = AllocaToPaddedAllocaMap.lookup(AI)) |
| 1588 | + DVI->replaceVariableLocationOp(V, NewAI); |
1593 | 1589 | }
|
1594 | 1590 | }
|
1595 | 1591 | }
|
|
0 commit comments