1 //===--------- Definition of the AddressSanitizer class ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares common infrastructure for AddressSanitizer and
10 // HWAddressSanitizer.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERCOMMON_H
14 #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERCOMMON_H
15 
16 #include "llvm/Analysis/CFG.h"
17 #include "llvm/Analysis/PostDominators.h"
18 #include "llvm/IR/Dominators.h"
19 #include "llvm/IR/Instruction.h"
20 #include "llvm/IR/IntrinsicInst.h"
21 #include "llvm/IR/Module.h"
22 
23 namespace llvm {
24 
25 class InterestingMemoryOperand {
26 public:
27   Use *PtrUse;
28   bool IsWrite;
29   Type *OpType;
30   uint64_t TypeSize;
31   MaybeAlign Alignment;
32   // The mask Value, if we're looking at a masked load/store.
33   Value *MaybeMask;
34 
35   InterestingMemoryOperand(Instruction *I, unsigned OperandNo, bool IsWrite,
36                            class Type *OpType, MaybeAlign Alignment,
37                            Value *MaybeMask = nullptr)
38       : IsWrite(IsWrite), OpType(OpType), Alignment(Alignment),
39         MaybeMask(MaybeMask) {
40     const DataLayout &DL = I->getModule()->getDataLayout();
41     TypeSize = DL.getTypeStoreSizeInBits(OpType);
42     PtrUse = &I->getOperandUse(OperandNo);
43   }
44 
45   Instruction *getInsn() { return cast<Instruction>(PtrUse->getUser()); }
46 
47   Value *getPtr() { return PtrUse->get(); }
48 };
49 
50 // Get AddressSanitizer parameters.
51 void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
52                                bool IsKasan, uint64_t *ShadowBase,
53                                int *MappingScale, bool *OrShadowOffset);
54 
55 } // namespace llvm
56 
57 #endif
58