[Expression] IR Instrumenters should have a UtilityFunction

Right now, IR Instrumenters take a DynamicCheckerFunctions object which
has all the UtilityFunctions used to instrument IR for expressions.
However, each Instrumenter (in practice) uses exactly one
UtilityFunction, so let's change the abstraction.

llvm-svn: 365696
This commit is contained in:
Alex Langford 2019-07-10 20:41:36 +00:00
parent cbe3ed17fa
commit 461a9d98d7
2 changed files with 18 additions and 18 deletions

View File

@ -1,5 +1,4 @@
//===-- IRDynamicChecks.h ---------------------------------------------*- C++
//-*-===//
//===-- IRDynamicChecks.h ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -68,8 +67,8 @@ public:
bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message);
std::unique_ptr<UtilityFunction> m_valid_pointer_check;
std::unique_ptr<UtilityFunction> m_objc_object_check;
std::shared_ptr<UtilityFunction> m_valid_pointer_check;
std::shared_ptr<UtilityFunction> m_objc_object_check;
};
/// \class IRDynamicChecks IRDynamicChecks.h

View File

@ -134,8 +134,9 @@ public:
///
/// \param[in] module
/// The module being instrumented.
Instrumenter(llvm::Module &module, DynamicCheckerFunctions &checker_functions)
: m_module(module), m_checker_functions(checker_functions),
Instrumenter(llvm::Module &module,
std::shared_ptr<UtilityFunction> checker_function)
: m_module(module), m_checker_function(checker_function),
m_i8ptr_ty(nullptr), m_intptr_ty(nullptr) {}
virtual ~Instrumenter() = default;
@ -296,8 +297,8 @@ protected:
InstVector m_to_instrument; ///< List of instructions the inspector found
llvm::Module &m_module; ///< The module which is being instrumented
DynamicCheckerFunctions
&m_checker_functions; ///< The dynamic checker functions for the process
std::shared_ptr<UtilityFunction>
m_checker_function; ///< The dynamic checker function for the process
private:
PointerType *m_i8ptr_ty;
@ -307,8 +308,8 @@ private:
class ValidPointerChecker : public Instrumenter {
public:
ValidPointerChecker(llvm::Module &module,
DynamicCheckerFunctions &checker_functions)
: Instrumenter(module, checker_functions),
std::shared_ptr<UtilityFunction> checker_function)
: Instrumenter(module, checker_function),
m_valid_pointer_check_func(nullptr) {}
~ValidPointerChecker() override = default;
@ -322,8 +323,8 @@ protected:
PrintValue(inst).c_str());
if (!m_valid_pointer_check_func)
m_valid_pointer_check_func = BuildPointerValidatorFunc(
m_checker_functions.m_valid_pointer_check->StartAddress());
m_valid_pointer_check_func =
BuildPointerValidatorFunc(m_checker_function->StartAddress());
llvm::Value *dereferenced_ptr = nullptr;
@ -366,8 +367,8 @@ private:
class ObjcObjectChecker : public Instrumenter {
public:
ObjcObjectChecker(llvm::Module &module,
DynamicCheckerFunctions &checker_functions)
: Instrumenter(module, checker_functions),
std::shared_ptr<UtilityFunction> checker_function)
: Instrumenter(module, checker_function),
m_objc_object_check_func(nullptr) {}
~ObjcObjectChecker() override = default;
@ -391,8 +392,8 @@ protected:
// InspectInstruction wouldn't have registered it
if (!m_objc_object_check_func)
m_objc_object_check_func = BuildObjectCheckerFunc(
m_checker_functions.m_objc_object_check->StartAddress());
m_objc_object_check_func =
BuildObjectCheckerFunc(m_checker_function->StartAddress());
// id objc_msgSend(id theReceiver, SEL theSelector, ...)
@ -552,7 +553,7 @@ bool IRDynamicChecks::runOnModule(llvm::Module &M) {
}
if (m_checker_functions.m_valid_pointer_check) {
ValidPointerChecker vpc(M, m_checker_functions);
ValidPointerChecker vpc(M, m_checker_functions.m_valid_pointer_check);
if (!vpc.Inspect(*function))
return false;
@ -562,7 +563,7 @@ bool IRDynamicChecks::runOnModule(llvm::Module &M) {
}
if (m_checker_functions.m_objc_object_check) {
ObjcObjectChecker ooc(M, m_checker_functions);
ObjcObjectChecker ooc(M, m_checker_functions.m_objc_object_check);
if (!ooc.Inspect(*function))
return false;