diff options
author | Sean Callanan <scallanan@apple.com> | 2013-12-20 19:55:02 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2013-12-20 19:55:02 +0000 |
commit | 82710a81374cb3413cbe553d0df95bc1948cd2e7 (patch) | |
tree | 3a817dcf68fee568c8e96a0c10d4a056a24fb0dc /source/Expression/IRDynamicChecks.cpp | |
parent | ec72d4185fd865827543ec96ba40a0fb5538f185 (diff) |
Updated our IR processing to reflect best practices
for making pointer-valued constants.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@197829 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'source/Expression/IRDynamicChecks.cpp')
-rw-r--r-- | source/Expression/IRDynamicChecks.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/source/Expression/IRDynamicChecks.cpp b/source/Expression/IRDynamicChecks.cpp index ed47fe31a..a75a0fca9 100644 --- a/source/Expression/IRDynamicChecks.cpp +++ b/source/Expression/IRDynamicChecks.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" @@ -145,7 +146,8 @@ public: DynamicCheckerFunctions &checker_functions) : m_module(module), m_checker_functions(checker_functions), - m_i8ptr_ty(NULL) + m_i8ptr_ty(NULL), + m_intptr_ty(NULL) { } @@ -279,8 +281,6 @@ protected: //------------------------------------------------------------------ llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address) { - IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), 64); - llvm::Type *param_array[1]; param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy()); @@ -289,7 +289,7 @@ protected: FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true); PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); - Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false); + Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); } @@ -305,8 +305,6 @@ protected: //------------------------------------------------------------------ llvm::Value *BuildObjectCheckerFunc(lldb::addr_t start_address) { - IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), 64); - llvm::Type *param_array[2]; param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy()); @@ -316,7 +314,7 @@ protected: FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true); PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); - Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false); + Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); } @@ -328,6 +326,18 @@ protected: return m_i8ptr_ty; } + IntegerType *GetIntptrTy() + { + if (!m_intptr_ty) + { + llvm::DataLayout data_layout(&m_module); + + m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), data_layout.getPointerSizeInBits()); + } + + return m_intptr_ty; + } + typedef std::vector <llvm::Instruction *> InstVector; typedef InstVector::iterator InstIterator; @@ -336,6 +346,7 @@ protected: DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process private: PointerType *m_i8ptr_ty; + IntegerType *m_intptr_ty; }; class ValidPointerChecker : public Instrumenter |