aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ByteCode/ByteCodeEmitter.cpp')
-rw-r--r--clang/lib/AST/ByteCode/ByteCodeEmitter.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 3288585..1d71708 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -135,25 +135,25 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
/// Helper to write bytecode and bail out if 32-bit offsets become invalid.
/// Pointers will be automatically marshalled as 32-bit IDs.
template <typename T>
-static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
- bool &Success) {
+static void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
+ const T &Val, bool &Success) {
+ size_t ValPos = Code.size();
size_t Size;
if constexpr (std::is_pointer_v<T>)
- Size = sizeof(uint32_t);
+ Size = align(sizeof(uint32_t));
else
- Size = sizeof(T);
+ Size = align(sizeof(T));
- if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+ if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
Success = false;
return;
}
// Access must be aligned!
- size_t ValPos = align(Code.size());
- Size = align(Size);
+ assert(aligned(ValPos));
assert(aligned(ValPos + Size));
- Code.resize(ValPos + Size);
+ Code.resize_for_overwrite(ValPos + Size);
if constexpr (!std::is_pointer_v<T>) {
new (Code.data() + ValPos) T(Val);
@@ -166,46 +166,45 @@ static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
/// Emits a serializable value. These usually (potentially) contain
/// heap-allocated memory and aren't trivially copyable.
template <typename T>
-static void emitSerialized(std::vector<std::byte> &Code, const T &Val,
+static void emitSerialized(llvm::SmallVectorImpl<std::byte> &Code, const T &Val,
bool &Success) {
- size_t Size = Val.bytesToSerialize();
+ size_t ValPos = Code.size();
+ size_t Size = align(Val.bytesToSerialize());
- if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+ if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
Success = false;
return;
}
// Access must be aligned!
- assert(aligned(Code.size()));
- size_t ValPos = Code.size();
- Size = align(Size);
+ assert(aligned(ValPos));
assert(aligned(ValPos + Size));
- Code.resize(ValPos + Size);
+ Code.resize_for_overwrite(ValPos + Size);
Val.serialize(Code.data() + ValPos);
}
template <>
-void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
- bool &Success) {
+void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
+ const Floating &Val, bool &Success) {
emitSerialized(Code, Val, Success);
}
template <>
-void emit(Program &P, std::vector<std::byte> &Code,
+void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
const IntegralAP<false> &Val, bool &Success) {
emitSerialized(Code, Val, Success);
}
template <>
-void emit(Program &P, std::vector<std::byte> &Code, const IntegralAP<true> &Val,
- bool &Success) {
+void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
+ const IntegralAP<true> &Val, bool &Success) {
emitSerialized(Code, Val, Success);
}
template <>
-void emit(Program &P, std::vector<std::byte> &Code, const FixedPoint &Val,
- bool &Success) {
+void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
+ const FixedPoint &Val, bool &Success) {
emitSerialized(Code, Val, Success);
}
@@ -217,7 +216,9 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
// The opcode is followed by arguments. The source info is
// attached to the address after the opcode.
emit(P, Code, Op, Success);
- if (SI)
+ if (LocOverride)
+ SrcMap.emplace_back(Code.size(), *LocOverride);
+ else if (SI)
SrcMap.emplace_back(Code.size(), SI);
(..., emit(P, Code, Args, Success));