xref: /llvm-project/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h (revision 2d209d964a17687f70299d756a7b5e9fa342e0b4)
1cfe36e4cSJann Horn //===--------- Definition of the AddressSanitizer class ---------*- C++ -*-===//
2cfe36e4cSJann Horn //
3c874dd53SChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4c874dd53SChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
5c874dd53SChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6cfe36e4cSJann Horn //
7cfe36e4cSJann Horn //===----------------------------------------------------------------------===//
8cfe36e4cSJann Horn //
9cfe36e4cSJann Horn // This file declares common infrastructure for AddressSanitizer and
10cfe36e4cSJann Horn // HWAddressSanitizer.
11cfe36e4cSJann Horn //
12cfe36e4cSJann Horn //===----------------------------------------------------------------------===//
13cfe36e4cSJann Horn #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERCOMMON_H
14cfe36e4cSJann Horn #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERCOMMON_H
15cfe36e4cSJann Horn 
16d23f26f0SFlorian Mayer #include "llvm/Analysis/CFG.h"
17d23f26f0SFlorian Mayer #include "llvm/Analysis/PostDominators.h"
18d23f26f0SFlorian Mayer #include "llvm/IR/Dominators.h"
19cfe36e4cSJann Horn #include "llvm/IR/Instruction.h"
20abf8ed8aSFlorian Mayer #include "llvm/IR/IntrinsicInst.h"
21cfe36e4cSJann Horn #include "llvm/IR/Module.h"
22cfe36e4cSJann Horn 
23cfe36e4cSJann Horn namespace llvm {
24cfe36e4cSJann Horn 
25cfe36e4cSJann Horn class InterestingMemoryOperand {
26cfe36e4cSJann Horn public:
27cfe36e4cSJann Horn   Use *PtrUse;
28cfe36e4cSJann Horn   bool IsWrite;
29c82cb5d0SNikita Popov   Type *OpType;
3081b7f115SSander de Smalen   TypeSize TypeStoreSize = TypeSize::getFixed(0);
3187e2751cSGuillaume Chatelet   MaybeAlign Alignment;
32cfe36e4cSJann Horn   // The mask Value, if we're looking at a masked load/store.
33cfe36e4cSJann Horn   Value *MaybeMask;
3442601e11SYeting Kuo   // The EVL Value, if we're looking at a vp intrinsic.
3542601e11SYeting Kuo   Value *MaybeEVL;
36deccb2dfSYeting Kuo   // The Stride Value, if we're looking at a strided load/store.
37deccb2dfSYeting Kuo   Value *MaybeStride;
38cfe36e4cSJann Horn 
39cfe36e4cSJann Horn   InterestingMemoryOperand(Instruction *I, unsigned OperandNo, bool IsWrite,
4087e2751cSGuillaume Chatelet                            class Type *OpType, MaybeAlign Alignment,
4142601e11SYeting Kuo                            Value *MaybeMask = nullptr,
42deccb2dfSYeting Kuo                            Value *MaybeEVL = nullptr,
43deccb2dfSYeting Kuo                            Value *MaybeStride = nullptr)
IsWrite(IsWrite)44c82cb5d0SNikita Popov       : IsWrite(IsWrite), OpType(OpType), Alignment(Alignment),
45deccb2dfSYeting Kuo         MaybeMask(MaybeMask), MaybeEVL(MaybeEVL), MaybeStride(MaybeStride) {
46*2d209d96SNikita Popov     const DataLayout &DL = I->getDataLayout();
4745b6a33bSPhilip Reames     TypeStoreSize = DL.getTypeStoreSizeInBits(OpType);
48cfe36e4cSJann Horn     PtrUse = &I->getOperandUse(OperandNo);
49cfe36e4cSJann Horn   }
50cfe36e4cSJann Horn 
getInsn()51cfe36e4cSJann Horn   Instruction *getInsn() { return cast<Instruction>(PtrUse->getUser()); }
52cfe36e4cSJann Horn 
getPtr()53cfe36e4cSJann Horn   Value *getPtr() { return PtrUse->get(); }
54cfe36e4cSJann Horn };
55cfe36e4cSJann Horn 
5605a8c0b5SKirill Stoimenov // Get AddressSanitizer parameters.
5705a8c0b5SKirill Stoimenov void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
5805a8c0b5SKirill Stoimenov                                bool IsKasan, uint64_t *ShadowBase,
5905a8c0b5SKirill Stoimenov                                int *MappingScale, bool *OrShadowOffset);
6005a8c0b5SKirill Stoimenov 
61cfe36e4cSJann Horn } // namespace llvm
62cfe36e4cSJann Horn 
63cfe36e4cSJann Horn #endif
64