Skip to content

Commit 70e61e0

Browse files
agampemeta-codesync[bot]
authored andcommitted
Deal with clang-tidy operator= suggestions
Summary: As title. Reviewed By: ssj933 Differential Revision: D88289985 fbshipit-source-id: 2d8a66b19dbf2c4349614eadfe68fd045a3e8368
1 parent 3248cf8 commit 70e61e0

File tree

9 files changed

+97
-9
lines changed

9 files changed

+97
-9
lines changed

libredex/IRInstruction.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ IRInstruction::IRInstruction(const IRInstruction& other)
3030
: m_opcode(other.m_opcode),
3131
m_num_srcs(other.m_num_srcs),
3232
m_dest(other.m_dest),
33+
// TODO: This can trigger undefined behavior.
3334
m_literal(other.m_literal) {
3435
if (m_num_srcs <= MAX_NUM_INLINE_SRCS) {
3536
for (src_index_t i = 0; i < m_num_srcs; ++i) {
@@ -44,6 +45,26 @@ IRInstruction::IRInstruction(const IRInstruction& other)
4445
}
4546
}
4647

48+
IRInstruction& IRInstruction::operator=(const IRInstruction& other) {
49+
m_opcode = other.m_opcode;
50+
m_num_srcs = other.m_num_srcs;
51+
m_dest = other.m_dest;
52+
// TODO: This can trigger undefined behavior.
53+
m_literal = other.m_literal;
54+
if (m_num_srcs <= MAX_NUM_INLINE_SRCS) {
55+
for (src_index_t i = 0; i < m_num_srcs; ++i) {
56+
m_inline_srcs[i] = other.m_inline_srcs[i];
57+
}
58+
} else {
59+
m_srcs = new reg_t[m_num_srcs];
60+
std::memcpy(m_srcs, other.m_srcs, m_num_srcs * sizeof(reg_t));
61+
}
62+
if (other.has_data()) {
63+
m_data = other.m_data->clone();
64+
}
65+
return *this;
66+
}
67+
4768
IRInstruction::~IRInstruction() {
4869
if (m_num_srcs > MAX_NUM_INLINE_SRCS) {
4970
delete[] m_srcs;

libredex/IRInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class IRInstruction final {
139139
public:
140140
explicit IRInstruction(IROpcode op);
141141
IRInstruction(const IRInstruction&);
142+
IRInstruction& operator=(const IRInstruction&);
142143
~IRInstruction();
143144

144145
/*

libredex/IRList.cpp

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,30 @@ MethodItemEntry::MethodItemEntry(const MethodItemEntry& that)
125125
}
126126
}
127127

128-
MethodItemEntry::~MethodItemEntry() {
129-
switch (type) {
128+
namespace {
129+
130+
void free_mie_contents(MethodItemEntry& mie) {
131+
switch (mie.type) {
130132
case MFLOW_TRY:
131-
delete tentry;
133+
delete mie.tentry;
132134
break;
133135
case MFLOW_CATCH:
134-
delete centry;
136+
delete mie.centry;
135137
break;
136138
case MFLOW_TARGET:
137-
delete target;
139+
delete mie.target;
138140
break;
139141
case MFLOW_DEBUG:
140-
dbgop.~unique_ptr<DexDebugInstruction>();
142+
mie.dbgop.~unique_ptr<DexDebugInstruction>();
141143
break;
142144
case MFLOW_POSITION:
143-
pos.~unique_ptr<DexPosition>();
145+
mie.pos.~unique_ptr<DexPosition>();
144146
break;
145147
case MFLOW_SOURCE_BLOCK:
146-
src_block.~unique_ptr<SourceBlock>();
148+
mie.src_block.~unique_ptr<SourceBlock>();
147149
break;
148150
case MFLOW_DEX_OPCODE:
149-
delete dex_insn;
151+
delete mie.dex_insn;
150152
break;
151153
case MFLOW_OPCODE:
152154
case MFLOW_FALLTHROUGH:
@@ -155,6 +157,48 @@ MethodItemEntry::~MethodItemEntry() {
155157
}
156158
}
157159

160+
} // namespace
161+
162+
MethodItemEntry& MethodItemEntry::operator=(const MethodItemEntry& that) {
163+
if (this == &that) {
164+
return *this;
165+
}
166+
free_mie_contents(*this);
167+
type = that.type;
168+
switch (type) {
169+
case MFLOW_TRY:
170+
tentry = that.tentry;
171+
break;
172+
case MFLOW_CATCH:
173+
centry = that.centry;
174+
break;
175+
case MFLOW_OPCODE:
176+
insn = that.insn;
177+
break;
178+
case MFLOW_DEX_OPCODE:
179+
dex_insn = that.dex_insn;
180+
break;
181+
case MFLOW_TARGET:
182+
target = that.target;
183+
break;
184+
case MFLOW_DEBUG:
185+
new (&dbgop) std::unique_ptr<DexDebugInstruction>(that.dbgop->clone());
186+
break;
187+
case MFLOW_POSITION:
188+
new (&pos) std::unique_ptr<DexPosition>(new DexPosition(*that.pos));
189+
break;
190+
case MFLOW_SOURCE_BLOCK:
191+
new (&src_block)
192+
std::unique_ptr<SourceBlock>(new SourceBlock(*that.src_block));
193+
break;
194+
case MFLOW_FALLTHROUGH:
195+
break;
196+
}
197+
return *this;
198+
}
199+
200+
MethodItemEntry::~MethodItemEntry() { free_mie_contents(*this); }
201+
158202
void MethodItemEntry::replace_ir_with_dex(DexInstruction* dex_insn) {
159203
always_assert(type == MFLOW_OPCODE);
160204
delete this->insn;
@@ -985,6 +1029,19 @@ void IRList::insn_clear_and_dispose() {
9851029
});
9861030
}
9871031

1032+
SourceBlock& SourceBlock::operator=(const SourceBlock& other) {
1033+
if (this == &other) {
1034+
return *this;
1035+
}
1036+
src = other.src;
1037+
next = std::unique_ptr<SourceBlock>(
1038+
other.next == nullptr ? nullptr : new SourceBlock(*other.next));
1039+
id = other.id;
1040+
always_assert(vals_size == other.vals_size);
1041+
m_storage = make_storage(other.m_storage.get());
1042+
return *this;
1043+
}
1044+
9881045
std::unique_ptr<SourceBlock::Storage, SourceBlock::FreeDeleter>
9891046
SourceBlock::make_storage(size_t vals_size, const Val& val) {
9901047
if (vals_size == 0) {

libredex/IRList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ struct SourceBlock {
193193
id(other.id),
194194
vals_size(other.vals_size),
195195
m_storage(make_storage(other.m_storage.get())) {}
196+
SourceBlock& operator=(const SourceBlock&);
196197

197198
boost::optional<float> get_val(size_t i) const {
198199
const auto& val = get_at(i);
@@ -583,6 +584,7 @@ struct MethodItemEntry {
583584
std::unique_ptr<SourceBlock> src_block;
584585
};
585586
MethodItemEntry(const MethodItemEntry&);
587+
MethodItemEntry& operator=(const MethodItemEntry&);
586588
explicit MethodItemEntry(DexInstruction* dex_insn) {
587589
this->type = MFLOW_DEX_OPCODE;
588590
this->dex_insn = dex_insn;

libredex/PluginRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class PluginRegistry {
8484
*/
8585
PluginRegistry() {}
8686
PluginRegistry(const PluginRegistry&) = delete;
87+
PluginRegistry& operator=(const PluginRegistry&) = delete;
8788

8889
UnorderedMap<std::string, std::unique_ptr<Plugin>> m_registered_passes;
8990
};

libredex/ProguardConfiguration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct KeepSpec {
106106
// instance of a KeepSpec in Redex. This makes it efficient and simple to
107107
// represent these KeepSpecs in the reachability graph.
108108
KeepSpec(const KeepSpec&) = delete;
109+
KeepSpec& operator=(const KeepSpec&) = delete;
109110

110111
friend bool operator==(const KeepSpec& lhs, const KeepSpec& rhs);
111112
friend std::ostream& operator<<(std::ostream&, const KeepSpec&);
@@ -203,6 +204,7 @@ struct ProguardConfiguration {
203204

204205
ProguardConfiguration() = default;
205206
ProguardConfiguration(const ProguardConfiguration&) = delete;
207+
ProguardConfiguration& operator=(const ProguardConfiguration&) = delete;
206208
};
207209

208210
namespace impl {

opt/optimize_enums/EnumTransformer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ class EnumTransformer final {
11611161
}
11621162

11631163
EnumTransformer(const EnumTransformer&) = delete;
1164+
EnumTransformer& operator=(const EnumTransformer&) = delete;
11641165

11651166
void run() {
11661167
auto scope = build_class_scope(m_stores);

opt/optimize_resources/OptimizeResources.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ struct ReachableResourcesPluginRegistry {
6565
ReachableResourcesPluginRegistry() {}
6666
ReachableResourcesPluginRegistry(const ReachableResourcesPluginRegistry&) =
6767
delete;
68+
ReachableResourcesPluginRegistry& operator=(
69+
const ReachableResourcesPluginRegistry&) = delete;
6870

6971
std::vector<ReachableResourcesPlugin*> m_registered_plugins;
7072
};

tools/tool/ToolRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct ToolRegistry {
4242
*/
4343
ToolRegistry() {}
4444
ToolRegistry(const ToolRegistry&) = delete;
45+
ToolRegistry& operator=(const ToolRegistry&) = delete;
4546

4647
std::vector<Tool*> m_registered_tools;
4748
};

0 commit comments

Comments
 (0)