Skip to content

Commit e26b42c

Browse files
authored
[lldb] Avoid calling DataLayout constructor accepting Module pointer (NFC) (llvm#102839)
The constructor initializes `*this` with a copy of `M->getDataLayout()`, which can just be spelled as `DataLayout DL = M->getDataLayout()`. In all places where the constructor is used, Module outlives DataLayout, so store a reference to it instead of cloning. Pull Request: llvm#102839
1 parent b812e57 commit e26b42c

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

lldb/source/Expression/IRInterpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class InterpreterStackFrame {
9696
typedef std::map<const Value *, lldb::addr_t> ValueMap;
9797

9898
ValueMap m_values;
99-
DataLayout &m_target_data;
99+
const DataLayout &m_target_data;
100100
lldb_private::IRExecutionUnit &m_execution_unit;
101101
const BasicBlock *m_bb = nullptr;
102102
const BasicBlock *m_prev_bb = nullptr;
@@ -110,7 +110,7 @@ class InterpreterStackFrame {
110110
lldb::ByteOrder m_byte_order;
111111
size_t m_addr_byte_size;
112112

113-
InterpreterStackFrame(DataLayout &target_data,
113+
InterpreterStackFrame(const DataLayout &target_data,
114114
lldb_private::IRExecutionUnit &execution_unit,
115115
lldb::addr_t stack_frame_bottom,
116116
lldb::addr_t stack_frame_top)
@@ -703,7 +703,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
703703
s.c_str());
704704
}
705705

706-
DataLayout data_layout(&module);
706+
const DataLayout &data_layout = module.getDataLayout();
707707

708708
InterpreterStackFrame frame(data_layout, execution_unit, stack_frame_bottom,
709709
stack_frame_top);

lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,9 @@ class Instrumenter {
280280

281281
IntegerType *GetIntptrTy() {
282282
if (!m_intptr_ty) {
283-
llvm::DataLayout data_layout(&m_module);
284-
285-
m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
286-
data_layout.getPointerSizeInBits());
283+
m_intptr_ty = llvm::Type::getIntNTy(
284+
m_module.getContext(),
285+
m_module.getDataLayout().getPointerSizeInBits());
287286
}
288287

289288
return m_intptr_ty;

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ bool IRForTarget::runOnModule(Module &llvm_module) {
16061606
lldb_private::Log *log(GetLog(LLDBLog::Expressions));
16071607

16081608
m_module = &llvm_module;
1609-
m_target_data = std::make_unique<DataLayout>(m_module);
1609+
m_target_data = &m_module->getDataLayout();
16101610
m_intptr_ty = llvm::Type::getIntNTy(m_module->getContext(),
16111611
m_target_data->getPointerSizeInBits());
16121612

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ class IRForTarget {
331331
lldb_private::TypeFromParser m_result_type;
332332
/// The module being processed, or NULL if that has not been determined yet.
333333
llvm::Module *m_module = nullptr;
334-
/// The target data for the module being processed, or NULL if there is no
334+
/// The target data for the module being processed, or nullptr if there is no
335335
/// module.
336-
std::unique_ptr<llvm::DataLayout> m_target_data;
336+
const llvm::DataLayout *m_target_data = nullptr;
337337
/// The DeclMap containing the Decls
338338
lldb_private::ClangExpressionDeclMap *m_decl_map;
339339
/// The address of the function CFStringCreateWithBytes, cast to the

0 commit comments

Comments
 (0)