|
29 | 29 | #include "llvm/Analysis/MemoryBuiltins.h"
|
30 | 30 | #include "llvm/Analysis/StackSafetyAnalysis.h"
|
31 | 31 | #include "llvm/Analysis/TargetLibraryInfo.h"
|
| 32 | +#include "llvm/Analysis/TargetTransformInfo.h" |
32 | 33 | #include "llvm/Analysis/ValueTracking.h"
|
33 | 34 | #include "llvm/BinaryFormat/MachO.h"
|
34 | 35 | #include "llvm/Demangle/Demangle.h"
|
@@ -803,7 +804,8 @@ struct AddressSanitizer {
|
803 | 804 |
|
804 | 805 | bool ignoreAccess(Instruction *Inst, Value *Ptr);
|
805 | 806 | void getInterestingMemoryOperands(
|
806 |
| - Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting); |
| 807 | + Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting, |
| 808 | + const TargetTransformInfo *TTI); |
807 | 809 |
|
808 | 810 | void instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
|
809 | 811 | InterestingMemoryOperand &O, bool UseCalls,
|
@@ -843,7 +845,7 @@ struct AddressSanitizer {
|
843 | 845 | void instrumentMemIntrinsic(MemIntrinsic *MI, RuntimeCallInserter &RTCI);
|
844 | 846 | Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
|
845 | 847 | bool suppressInstrumentationSiteForDebug(int &Instrumented);
|
846 |
| - bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI); |
| 848 | + bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI, const TargetTransformInfo *TTI); |
847 | 849 | bool maybeInsertAsanInitAtFunctionEntry(Function &F);
|
848 | 850 | bool maybeInsertDynamicShadowAtFunctionEntry(Function &F);
|
849 | 851 | void markEscapedLocalAllocas(Function &F);
|
@@ -1314,7 +1316,8 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
|
1314 | 1316 | Options.MaxInlinePoisoningSize, Options.CompileKernel, Options.Recover,
|
1315 | 1317 | Options.UseAfterScope, Options.UseAfterReturn);
|
1316 | 1318 | const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
|
1317 |
| - Modified |= FunctionSanitizer.instrumentFunction(F, &TLI); |
| 1319 | + const TargetTransformInfo &TTI = FAM.getResult<TargetIRAnalysis>(F); |
| 1320 | + Modified |= FunctionSanitizer.instrumentFunction(F, &TLI, &TTI); |
1318 | 1321 | }
|
1319 | 1322 | Modified |= ModuleSanitizer.instrumentModule();
|
1320 | 1323 | if (!Modified)
|
@@ -1452,7 +1455,8 @@ bool AddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) {
|
1452 | 1455 | }
|
1453 | 1456 |
|
1454 | 1457 | void AddressSanitizer::getInterestingMemoryOperands(
|
1455 |
| - Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting) { |
| 1458 | + Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting, |
| 1459 | + const TargetTransformInfo *TTI) { |
1456 | 1460 | // Do not instrument the load fetching the dynamic shadow address.
|
1457 | 1461 | if (LocalDynamicShadow == I)
|
1458 | 1462 | return;
|
@@ -1570,6 +1574,12 @@ void AddressSanitizer::getInterestingMemoryOperands(
|
1570 | 1574 | break;
|
1571 | 1575 | }
|
1572 | 1576 | default:
|
| 1577 | + if (auto *II = dyn_cast<IntrinsicInst>(I)) { |
| 1578 | + MemIntrinsicInfo IntrInfo; |
| 1579 | + if (TTI->getTgtMemIntrinsic(II, IntrInfo)) |
| 1580 | + Interesting = IntrInfo.Interesting; |
| 1581 | + return; |
| 1582 | + } |
1573 | 1583 | for (unsigned ArgNo = 0; ArgNo < CI->arg_size(); ArgNo++) {
|
1574 | 1584 | if (!ClInstrumentByval || !CI->isByValArgument(ArgNo) ||
|
1575 | 1585 | ignoreAccess(I, CI->getArgOperand(ArgNo)))
|
@@ -2985,7 +2995,8 @@ bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
|
2985 | 2995 | }
|
2986 | 2996 |
|
2987 | 2997 | bool AddressSanitizer::instrumentFunction(Function &F,
|
2988 |
| - const TargetLibraryInfo *TLI) { |
| 2998 | + const TargetLibraryInfo *TLI, |
| 2999 | + const TargetTransformInfo *TTI) { |
2989 | 3000 | bool FunctionModified = false;
|
2990 | 3001 |
|
2991 | 3002 | // Do not apply any instrumentation for naked functions.
|
@@ -3038,7 +3049,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
|
3038 | 3049 | if (Inst.hasMetadata(LLVMContext::MD_nosanitize))
|
3039 | 3050 | continue;
|
3040 | 3051 | SmallVector<InterestingMemoryOperand, 1> InterestingOperands;
|
3041 |
| - getInterestingMemoryOperands(&Inst, InterestingOperands); |
| 3052 | + getInterestingMemoryOperands(&Inst, InterestingOperands, TTI); |
3042 | 3053 |
|
3043 | 3054 | if (!InterestingOperands.empty()) {
|
3044 | 3055 | for (auto &Operand : InterestingOperands) {
|
|
0 commit comments