Skip to content

Commit 7af3bdf

Browse files
committed
Address review feedback
1 parent c45c1c9 commit 7af3bdf

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
210210
}
211211
}
212212

213-
template <>
214-
void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
215-
bool &Success) {
213+
/// Emits a serializable value. These usually (potentially) contain
214+
/// heap-allocated memory and aren't trivially copyable.
215+
template <typename T>
216+
static void emitSerialized(std::vector<std::byte> &Code, const T &Val,
217+
bool &Success) {
216218
size_t Size = Val.bytesToSerialize();
217219

218220
if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
@@ -229,40 +231,22 @@ void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
229231
Val.serialize(Code.data() + ValPos);
230232
}
231233

234+
template <>
235+
void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
236+
bool &Success) {
237+
emitSerialized(Code, Val, Success);
238+
}
239+
232240
template <>
233241
void emit(Program &P, std::vector<std::byte> &Code,
234242
const IntegralAP<false> &Val, bool &Success) {
235-
size_t Size = Val.bytesToSerialize();
236-
237-
if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
238-
Success = false;
239-
return;
240-
}
241-
242-
// Access must be aligned!
243-
size_t ValPos = align(Code.size());
244-
Size = align(Size);
245-
assert(aligned(ValPos + Size));
246-
Code.resize(ValPos + Size);
247-
Val.serialize(Code.data() + ValPos);
243+
emitSerialized(Code, Val, Success);
248244
}
249245

250246
template <>
251247
void emit(Program &P, std::vector<std::byte> &Code, const IntegralAP<true> &Val,
252248
bool &Success) {
253-
size_t Size = Val.bytesToSerialize();
254-
255-
if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
256-
Success = false;
257-
return;
258-
}
259-
260-
// Access must be aligned!
261-
size_t ValPos = align(Code.size());
262-
Size = align(Size);
263-
assert(aligned(ValPos + Size));
264-
Code.resize(ValPos + Size);
265-
Val.serialize(Code.data() + ValPos);
249+
emitSerialized(Code, Val, Success);
266250
}
267251

268252
template <typename... Tys>

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ bool ByteCodeExprGen<Emitter>::emitConst(const APSInt &Value, PrimType Ty,
22152215
const Expr *E) {
22162216
if (Ty == PT_IntAPS)
22172217
return this->emitConstIntAPS(Value, E);
2218-
else if (Ty == PT_IntAP)
2218+
if (Ty == PT_IntAP)
22192219
return this->emitConstIntAP(Value, E);
22202220

22212221
if (Value.isSigned())

0 commit comments

Comments
 (0)